XyZskOther.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\controller;
  3. use app\model\CdssDisease;
  4. use app\model\VisitLimit;
  5. use think\facade\Request;
  6. /**
  7. * 西医疾病外部接口
  8. */
  9. class XyZskOther extends CommonEsController
  10. {
  11. /**
  12. * 2022/12/26
  13. * 西医疾病
  14. */
  15. public function getZskDetail()
  16. {
  17. $ip = $_SERVER['REMOTE_ADDR'];
  18. $checkIsCanVisit = $this->checkIsCanVisit($ip);
  19. if( ! $checkIsCanVisit) {
  20. return $this->_json_error('非法请求!');
  21. }
  22. $params = Request::only(
  23. [
  24. 'tag' , 'name'
  25. ]
  26. );
  27. $tag = $params['tag'] ?? '';
  28. $name = $params['name'] ?? '';
  29. if( ! $tag || ! $name) {
  30. return $this->_json_error('请求参数有误!');
  31. }
  32. $tags = ['medicine' , 'disease'];
  33. if( ! in_array($tag, $tags)) {
  34. return $this->_json_error('请求标识错误!');
  35. }
  36. /**
  37. * 药品
  38. */
  39. if('medicine' === $tag) {
  40. $model = '\app\model\CdssMedicine';
  41. $field = 'name';
  42. }
  43. /**
  44. * 疾病
  45. */
  46. if('disease' === $tag) {
  47. $model = '\app\model\CdssDisease';
  48. $field = 'name';
  49. }
  50. $detail = $model::where($field , $name)->find();
  51. unset($detail['id']);
  52. return $this->_json_succ(
  53. $detail
  54. );
  55. }
  56. /**
  57. * 检测访问
  58. */
  59. protected function checkIsCanVisit($ip)
  60. {
  61. $visit = VisitLimit::where('ip' , $ip)->find();
  62. if( ! $visit ) return false;
  63. if(0 >= $visit->already_visit_count) {
  64. return false;
  65. }
  66. return true;
  67. }
  68. }