Page.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\Page as PageModel;
  4. use app\common\library\Service;
  5. /**
  6. * 单页
  7. */
  8. class Page extends Base
  9. {
  10. protected $noNeedLogin = ['index', 'lists'];
  11. //单页详情
  12. public function index()
  13. {
  14. $keyword = $this->request->param('keyword');
  15. if ($keyword && !is_numeric($keyword)) {
  16. $page = PageModel::getByDiyname($keyword);
  17. } else {
  18. $id = $keyword ? $keyword : $this->request->param('id', '');
  19. $page = PageModel::get($id);
  20. }
  21. // if (!$page || $page['status'] != 'normal') {
  22. // $this->error('未找到指定的单页');
  23. // }
  24. if (!empty($page)) {
  25. $page->setInc('views');
  26. $image = $page->getData('image');
  27. $fields = explode(',', 'id,title,content,image,description,status,createtime');
  28. $page = array_intersect_key($page->toArray(), array_flip($fields));
  29. $page['content'] = Service::formatTplToUniapp($page['content']);
  30. $page['image'] = $image ? cdnurl($image, true) : $image;
  31. }
  32. $this->success('获取成功', $page);
  33. }
  34. //单页列表
  35. public function lists()
  36. {
  37. $type = $this->request->param('type');
  38. $list = PageModel::field('id,title,description,status,createtime')
  39. ->where('status', 'normal')->where('type', $type)->order('createtime desc')->paginate(15);
  40. $this->success('获取成功', $list);
  41. }
  42. }