<?php
// +----------------------------------------------------------------------
// | 奇乐自媒体管理系统 商业版 2019
// +----------------------------------------------------------------------
// | 官方网址：http://www.qilewl.com   
// +----------------------------------------------------------------------
// | 产品网址：http://www.qilecms.com
// +----------------------------------------------------------------------
// | Author:合肥奇乐网络科技有限公司 
// +----------------------------------------------------------------------
// | 版权说明：本产品为免费版，使用请保留底部版权
// +----------------------------------------------------------------------
namespace app\portal\controller;
use \think\Db;
class Index  extends Base
{
    public function index()
    {
      //获得幻灯片文章

      
       	 if($this->request->isAjax()){
                //获得最新新闻
              $param = $this->request->param();

		         $page   = !empty($param['page'])?intval($param['page']):1; //开始页面
		         $limit  = !empty($param['limit'])?intval($param['limit']):10; //分页数量
		         $where[] = ['status','=',1]; //审核通过
             $order ="create_time desc"; 
		         $total  = Db::name('article')->where($where)->count();
		         $list   = Db::name('article')->where($where)->order($order)->paginate($limit);
                
                 $cate = $this->getCache('articleCategory','cid');
                 

                 $data = [];
		         foreach($list as $k=>$v){
		            $data[$k]['id']     = $v['aid'];
		            $data[$k]['thumb']  = $v['thumb'];
		            $data[$k]['thumb1']  = $v['thumb1'];
		            $data[$k]['thumb2']  = $v['thumb2'];
		            $data[$k]['url']    = $v['url'];
		            $data[$k]['title']  = $v['title'];
		           
                    $data[$k]['username'] = get_nickname($v['uid']);
                    $data[$k]['uid'] = $v['uid'];
                    $data[$k]['create_time'] =date('Y-m-d',$v['create_time']);
                    $data[$k]['hits'] = $v['hits'];
                    $data[$k]['content'] = get_filter_str(htmlspecialchars_decode($v['content']),110);
                    $data[$k]['comment'] = $v['comment'];
                    $data[$k]['cname']   = $cate[$v['cid']]['cname'];
                    $data[$k]['url']     = url('@portal/article/detail',['aid'=>$v['aid']]);
                    $data[$k]['images']  = get_images_url(htmlspecialchars_decode($v['content']));
                    
		           
		         }
		        return json(['code'=>0,'msg'=>'success','pages'=>ceil($total/$limit),'data'=>$data]);
            }else{


            	 $cate = $this->getCache('articleCategory','cid');
               //获得顶置文章
               $top_map[] = ['attr_value','like',"%t%"];
               $top_map[] = ['status','=',1];
               $top_article_list = model('article')->listData($top_map,'','',2);
                $data = [];
		        foreach($top_article_list as $k=>$v){
                 	$top_article_list[$k]['cname']   = $cate[$v['cid']]['cname'];
               }
               $this->assign('top_article_list',$top_article_list);
               //获得幻灯文章
               $slide_map[] = ['attr_value','like',"%s%"];
               $slide_map[] = ['status','=',1];
               $slide_article_list = model('article')->listData($slide_map,'aid,title,thumb,thumb1,thumb2','',6);
           
		        foreach($slide_article_list as $k=>$v){
                 	$slide_article_list[$k]['cname']   = $cate[$v['cid']]['cname'];
               }

   
               $this->assign('slide_article_list',$slide_article_list);              

               	//24小时热文章
				    	$map3[] =['status','=',1];
				    	$map3[] =['thumb','<>',''];
				    	$hour   = time()-86400;
				    	$map3[] =['create_time','>',$hour];
				    	$hour_article_list = model('article')->listData($map3,'','hits desc',10);
				    	foreach($hour_article_list as $k=>$v){
				    		$hour_article_list[$k]['cname']   = $cate[$v['cid']]['cname'];
				    	}
			        	$this->assign('hour_article_list',$hour_article_list);


                 return $this->fetch();

            }

    }
}

