HospitallevelController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\HospitalLevel;
  5. class HospitallevelController extends Base
  6. {
  7. function index()
  8. {
  9. $weid = weid();
  10. $keyword = input('post.keyword', '', 'serach_in');
  11. $query = HospitalLevel::where(['weid' => $weid]);
  12. if (!empty($keyword)) {
  13. $query->where('title', 'like', '%' . $keyword . '%');
  14. }
  15. $datalist = $query->order('sort asc,id asc')->select()->toArray();
  16. if (empty($datalist)) {
  17. HospitalLevel::datainitial();
  18. $datalist = $query->order('sort asc,id asc')->select()->toArray();
  19. }
  20. $data['data'] = $datalist;
  21. return $this->json($data);
  22. }
  23. function listUpdate()
  24. {
  25. $data = only('id,status,sort');
  26. if (!$data['id']) throw new ValidateException('参数错误');
  27. HospitalLevel::update($data);
  28. return $this->json(['msg' => '操作成功']);
  29. }
  30. public function update()
  31. {
  32. $id = $this->request->post('id');
  33. $data = input('post.');
  34. unset($data['create_time']);
  35. if (empty($id)) {
  36. $data['weid'] = weid();
  37. try {
  38. $res = HospitalLevel::create($data);
  39. if ($res->id && empty($data['sort'])) {
  40. HospitalLevel::update(['sort' => $res->id, 'id' => $res->id]);
  41. }
  42. } catch (\Exception $e) {
  43. throw new ValidateException($e->getMessage());
  44. }
  45. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  46. } else {
  47. try {
  48. HospitalLevel::update($data);
  49. } catch (\Exception $e) {
  50. throw new ValidateException($e->getMessage());
  51. }
  52. return $this->json(['msg' => '修改成功']);
  53. }
  54. }
  55. function getInfo()
  56. {
  57. $id = $this->request->post('id', '', 'serach_in');
  58. if (!$id) throw new ValidateException('参数错误');
  59. $data = HospitalLevel::field('*')->find($id)->toArray();
  60. return $this->json(['data' => $data]);
  61. }
  62. function delete()
  63. {
  64. return $this->del(new HospitalLevel());
  65. }
  66. }