<?php

namespace app\mobile\controller;

use app\common\model\ArticleModel;
use app\common\model\NavigationModel;
use app\common\model\SinglePageModel;
use app\common\model\SlideModel;
use app\mobile\MobileBaseController;

class Index extends MobileBaseController
{
    public function index()
    {
        //轮播图
        $slide = SlideModel::where('tab', SlideModel::TAB_INDEX)
            ->where('status', SlideModel::STATUS_SHOW)
            ->order(['priority' => 'desc', 'id' => 'desc'])
            ->select();

        //导航图
        $navigation = NavigationModel::where('tab', NavigationModel::TAB_INDEX)
            ->where('status', SlideModel::STATUS_SHOW)
            ->order(['priority' => 'desc', 'id' => 'desc'])
            ->select();

        //文章
        $article = ArticleModel::where('status', ArticleModel::STATUS_PUBLISH)
            ->order(['priority' => 'desc', 'update_time' => 'desc'])
            ->limit(5)
            ->select();

        return view('', [
            'slide'      => $slide,
            'navigation' => $navigation,
            'article'    => $article,
        ]);
    }

    public function singlePage()
    {
        $field = input('get.field', 'about');
        if (!in_array($field, SinglePageModel::CODE)) {
            jump('文章不存在');
        }

        $value   = SinglePageModel::getConfigValue($field);
        $value   = explode("\n", $value);
        $content = '';
        foreach ($value as $v) {
            $content .= "<p>{$v}</p>";
        }

        return view('', [
            'content' => $content,
            'title'   => SinglePageModel::CODE_TITLE[$field],
        ]);
    }
}
