<?php
namespace app\index\controller;

use app\index\controller\Common;
use app\service\SeoService;
use app\service\ApiService;
use app\service\ArticleService;
use app\service\ArticleCategoryService;
use app\service\BreadcrumbService;
use app\service\MultilingualService;
use app\service\LinkService;

/**
 * 文章详情
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-01T21:51:08+0800
 */
class News extends Common {
	/**
     * 构造方法
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-11-30
     * @desc    description
     */
    public function __construct() {
        parent::__construct();
    }

	/**
     * 文章详情
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2021-11-08
     * @desc    description
     */
	public function Index() {
        // post搜索
        if(IS_POST) {
            $request_params = [];
            if(!empty($this->data_post['id'])) {
                $request_params['id'] = intval($this->data_post['id']);
            }
            return MyRedirect(MyUrl('index/news/index', $request_params));
        }

        $id = intval($this->data_request['id']);
        switch($id){
            case 12:
                $news_title = Mylang('common.menu_major_award_news');
                break;
            case 13:
                $news_title = Mylang('common.menu_hot_news');
                break;
            case 15:
                $news_title = Mylang('common.menu_divine_warning');
                break;
            default:
                $news_title = Mylang('common.menu_industry_trends');
                break;
        }



        $params = $this->data_request;

        // 条件
        $where = ArticleService::ArticleWhere($this->data_request);

        // 总数
        $total = ArticleService::ArticleTotal($where);

        // 分页
        $page_params = [
            'number'    =>  $this->page_size,
            'total'     =>  $total,
            'where'     =>  $this->data_request,
            'page'      =>  $this->page,
            'url'       =>  MyUrl('index/news/index'),
        ];
        $page = new \base\Page($page_params);

        // 获取列表
        $data_params = array_merge($params, [
            'm'      => $page->GetPageStarNumber(),
            'n'      => $this->page_size,
            'where'  => $where,
        ]);
        $ret = ArticleService::ArticleList($data_params);

        // 模板数据
        $assign = [
            // 列表数据
            'news_title'       => $news_title,
            'page_html'        => $page->GetPageHtml(),
            'data_list'        => $ret['data'],
            'params'           => $params,
            'article_footer_list'      => ArticleService::RecommendedArticleList(111,1),
            // 友情链接
            'link_list'   => LinkService::HomeLinkList(),
        ];

        $assign['home_seo_site_title'] = $news_title;
        $assign['home_seo_site_keywords'] = MyLang('lottery.home_seo_site_keywords');
        $assign['home_seo_site_description'] = MyLang('lottery.home_seo_site_description');

        // 数据赋值
        MyViewAssign($assign);
        return MyView();
	}

}
?>