<?php

namespace app\mobile\controller;

use app\common\model\ArticleCateModel;
use app\common\model\ArticleModel;
use app\mobile\MobileBaseController;

class Article extends MobileBaseController
{
    public function index()
    {
        $cate_list = ArticleCateModel::where('status', ArticleCateModel::STATUS_SHOW)
            ->order(['priority' => 'desc', 'id' => 'desc'])
            ->select();

        return view('', [
            'cate_list' => $cate_list,
            'cate_id'   => input('cate_id/d', 0),
        ]);
    }

    public function listArticle()
    {
        $map = $this->dealEqualInput(['cate_id']);

        $list = ArticleModel::where($map)
            ->order(['priority' => 'desc', 'id' => 'desc'])
            ->limit(input('limit', 10))
            ->page(input('page', 1))
            ->append(['type_text', 'status_text'])
            ->select();

        ajax_success($list);
    }

    public function detail()
    {
        $id = input('id/d', 0);
        empty($id) && jump('该文章不存在');

        $info = ArticleModel::where('status', ArticleCateModel::STATUS_SHOW)->find($id);
        empty($info) && jump('该文章不存在');

        return view('', [
            'info' => $info,
        ]);
    }
}
