Page.php 1.4 KB

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