1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace app\api\controller;
- use app\common\model\Page as PageModel;
- use app\common\library\Service;
- /**
- * 单页
- */
- class Page extends Base
- {
- protected $noNeedLogin = ['index', 'lists'];
- //单页详情
- public function index()
- {
- $keyword = $this->request->param('keyword');
- if ($keyword && !is_numeric($keyword)) {
- $page = PageModel::getByDiyname($keyword);
- } else {
- $id = $keyword ? $keyword : $this->request->param('id', '');
- $page = PageModel::get($id);
- }
- // if (!$page || $page['status'] != 'normal') {
- // $this->error('未找到指定的单页');
- // }
- if (!empty($page)) {
- $page->setInc('views');
- $image = $page->getData('image');
- $fields = explode(',', 'id,title,content,image,description,status,createtime');
- $page = array_intersect_key($page->toArray(), array_flip($fields));
- $page['content'] = Service::formatTplToUniapp($page['content']);
- $page['image'] = $image ? cdnurl($image, true) : $image;
- }
-
- $this->success('获取成功', $page);
- }
- //单页列表
- public function lists()
- {
- $type = $this->request->param('type');
- $list = PageModel::field('id,title,description,status,createtime')
- ->where('status', 'normal')->where('type', $type)->order('createtime desc')->paginate(15);
- $this->success('获取成功', $list);
- }
- }
|