MedicalCommunity.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\admin\controller\nhc;
  3. use app\admin\common\AdminController;
  4. use app\common\api\DictApi;
  5. use app\common\api\UploadApi;
  6. use think\facade\Db;
  7. /**
  8. * 医共体管理
  9. */
  10. class MedicalCommunity extends AdminController {
  11. public function index() {
  12. return view("");
  13. }
  14. public function list() {
  15. $order = trim($this->request->param("order")) ?: "desc";
  16. $offset = trim($this->request->param("offset")) ?: 0;
  17. $limit = trim($this->request->param("limit")) ?: 10;
  18. $name = trim($this->request->param("name"));
  19. $where = [];
  20. $where[] = ["status", "<>", 3];
  21. if ($name) {
  22. $where[] = ["name", "like", "%" . $name . "%"];
  23. }
  24. $count = Db::table("nhc_medical_community")->where($where)->count();
  25. $rows = Db::table("nhc_medical_community")->where($where)->limit($offset, $limit)->order("num asc,createTime " . $order)->select()->toArray();
  26. return ["total" => $count, "rows" => $rows];
  27. }
  28. public function add() {
  29. return view("edit");
  30. }
  31. public function edit() {
  32. $id = \StrUtil::getRequestDecodeParam($this->request, 'id');
  33. $info = Db::table("nhc_medical_community")->where("id", $id)->find();
  34. return view("edit", ["row" => $info]);
  35. }
  36. public function upsert() {
  37. $response_obj = new \StdClass();
  38. $response_obj->code = 500;
  39. $id = \StrUtil::getRequestDecodeParam($this->request, 'id');
  40. $where = [];
  41. if ($id) {
  42. $info = Db::table("nhc_medical_community")->where("id", $id)->find();
  43. if (!$info) {
  44. $response_obj->msg = '找不到记录';
  45. return \StrUtil::back($response_obj, 'MedicalCommunityInfo.callBack');
  46. }
  47. $where[] = ["id", "<>", $id];
  48. }
  49. $name = trim($this->request['name']);
  50. if (\StrUtil::isEmpOrNull($name)) {
  51. $response_obj->msg = '医共体名称不能为空';
  52. return \StrUtil::back($response_obj, 'MedicalCommunityInfo.callBack');
  53. }
  54. $where[] = ["name", "=", $name];
  55. $repeat = Db::table("nhc_medical_community")->where($where)->find();
  56. if ($repeat) {
  57. $response_obj->msg = '医共体名称已经被使用';
  58. return \StrUtil::back($response_obj, 'MedicalCommunityInfo.callBack');
  59. }
  60. $num = trim($this->request['num']);
  61. if (\StrUtil::isNotEmpAndNull($num) && !is_numeric($num)) {
  62. $response_obj->msg = '序号只能是数字';
  63. return \StrUtil::back($response_obj, 'MedicalCommunityInfo.callBack');
  64. }
  65. $status = trim($this->request['status']);
  66. if (\StrUtil::isEmpOrNull($status)) {
  67. $response_obj->msg = '启用状态不能为空';
  68. return \StrUtil::back($response_obj, 'MedicalCommunityInfo.callBack');
  69. }
  70. try {
  71. $data["name"] = $name;
  72. $data["status"] = $status;
  73. $data["num"] = $num;
  74. $data["description"] = \StrUtil::getRequestDecodeParam($this->request, "description");
  75. if ($id) {
  76. $data["id"] = $id;
  77. $data["updateTime"] = date("Y-m-d H:i:s");
  78. $data["updateUser"] = $this->user['uid'];
  79. Db::table("nhc_medical_community")->save($data);
  80. } else {
  81. $data["createTime"] = date("Y-m-d H:i:s");
  82. $data["createUser"] = $this->user['uid'];
  83. Db::table("nhc_medical_community")->insert($data);
  84. }
  85. $response_obj->code = 200;
  86. $response_obj->msg = '修改成功';
  87. return \StrUtil::back($response_obj, "MedicalCommunityInfo.callBack");
  88. } catch (\Exception $e) {
  89. $response_obj->msg = $e->getMessage();
  90. return \StrUtil::back($response_obj, "MedicalCommunityInfo.callBack");
  91. }
  92. }
  93. public function delete() {
  94. $id = \StrUtil::getRequestDecodeParam($this->request, 'id');
  95. if (\StrUtil::isEmpOrNull($id)) {
  96. return json(['code' => 500, 'msg' => '缺少参数']);
  97. }
  98. $data["id"] = $id;
  99. $data["status"] = 3;
  100. $data["updateTime"] = date("Y-m-d H:i:s");
  101. $data["updateUser"] = $this->user["uid"];
  102. try {
  103. Db::table("nhc_medical_community")->save($data);
  104. return json(['code' => 200, 'msg' => "删除成功"]);
  105. } catch (\Exception $e) {
  106. return json(['code' => 500, 'msg' => $e->getMessage()]);
  107. }
  108. }
  109. }