12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace app\api\controller;
- use app\api\controller\base\Base;
- class Specialist extends Base
- {
- private function getModel()
- {
- return new \app\common\model\Specialist();
- }
- public function index()
- {
- $post = $this->request->param();
- $validate = new \think\Validate([
- ['id', 'number'],
- ['module', 'number'],
- ['page', 'number'],
- ['pagenum', 'number|<=:1000']
- ]);
- if (!$validate->check($post)) {
- $this->json_error('提交失败:' . $validate->getError());
- }
- $where = [];
- if (isset($post['id'])) {
- $where['id'] = $post['id'];
- }
- if (isset($post['module'])) {
- $where['module'] = $post['module'];
- }
- if (isset($post['id'])) {
- $datalist = ($this->getModel())->where($where)->find();
- } else {
- $pagenum = $this->request->param('pagenum', 20, 'intval');
- $datalist = ($this->getModel())->where($where)->paginate($pagenum, true);
- /** @var \app\common\model\Specialist $item */
- foreach ($datalist as $key => $item) {
- $item['head_pic'] = geturl($item->head_pic, '', true);
- $datalist[$key] = $item;
- }
- }
- if (empty($datalist)) {
- $this->json_error("没有数据");
- }
- $this->json_success("查询成功", $datalist);
- }
- }
|