Specialist.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. ['module', 'number'],
  16. ['page', 'number'],
  17. ['pagenum', 'number|<=:1000']
  18. ]);
  19. if (!$validate->check($post)) {
  20. $this->json_error('提交失败:' . $validate->getError());
  21. }
  22. $where = [];
  23. if (isset($post['id'])) {
  24. $where['id'] = $post['id'];
  25. }
  26. if (isset($post['module'])) {
  27. $where['module'] = $post['module'];
  28. }
  29. if (isset($post['id'])) {
  30. $datalist = ($this->getModel())->where($where)->find();
  31. } else {
  32. $pagenum = $this->request->param('pagenum', 20, 'intval');
  33. $datalist = ($this->getModel())->where($where)->paginate($pagenum, true);
  34. /** @var \app\common\model\Specialist $item */
  35. foreach ($datalist as $key => $item) {
  36. $item['head_pic'] = geturl($item->head_pic, '', true);
  37. $datalist[$key] = $item;
  38. }
  39. }
  40. if (empty($datalist)) {
  41. $this->json_error("没有数据");
  42. }
  43. $this->json_success("查询成功", $datalist);
  44. }
  45. }