Specialist.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. /** @var \app\common\model\Specialist $item */
  31. foreach ($datalist as $key => $item) {
  32. $item['head_pic'] = geturl($item->head_pic, '', true);
  33. $datalist[$key] = $item;
  34. }
  35. }
  36. if (empty($datalist)) {
  37. $this->json_error("没有数据");
  38. }
  39. $this->json_success("查询成功", $datalist);
  40. }
  41. }