Specialist.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\controller\base\Base;
  4. class Specialist extends Base
  5. {
  6. private function getModel()
  7. {
  8. return new \app\common\model\Specialist();
  9. }
  10. public function index()
  11. {
  12. $post = $this->request->param();
  13. $validate = new \think\Validate([
  14. ['id', 'number'],
  15. ['page', 'number'],
  16. ['pagenum', 'number|<=:1000']
  17. ]);
  18. if (!$validate->check($post)) {
  19. $this->json_error('提交失败:' . $validate->getError());
  20. }
  21. $where = [];
  22. if (isset($post['id'])) {
  23. $where['id'] = $post['id'];
  24. }
  25. if (isset($post['id'])) {
  26. $datalist = ($this->getModel())->where($where)->find();
  27. } else {
  28. $pagenum = $this->request->param('pagenum', 20, 'intval');
  29. $datalist = ($this->getModel())->where($where)->paginate($pagenum, true);
  30. }
  31. if (empty($datalist)) {
  32. $this->json_error("没有数据");
  33. }
  34. $this->json_success("查询成功", $datalist);
  35. }
  36. }