<?php
/** App登录控制器
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaoq <xiaoq@570035208.com>
 */

namespace Wxsmall\Controller;
class ArticleController extends BaseController {
	public function _initialize(){
        parent::_initialize ();
    }
    /**
     *帮助中心
     */
    public function help() {
        $return=array('status'=>1);
        $data=D("Mobile/Article")->help();
        $cat_info=$data['cat_info'];
        $return['data']['info']=$cat_info;
        $this->ajaxReturn($return);
    }
    /**
     *文章列表
     */
    // public function article_list() {
    //     $return=array('status'=>1);
    //     $article_cat_list = D('Mobile/Article')->article_cat_list();
    //     $return['data']['article_cat_list']=$article_cat_list;
    //     $catid=I('id');//分类id
    //     $data=D('Mobile/Article')->article_list($catid);
    //     $return['data']['list']=$data['article_list'];
    //     $return['data']['catname']=$data['catname'];
    //     $this->ajaxReturn($return);
    // }
    public function article_list() {
        $article_cat_list = D('Mobile/Article')->article_cat_list();
        $catid=I('catid');//分类id
        $param=I('param.');
        if(empty($catid)){
            $param['is_tuijian'] = 1;
        }else{
            $param['is_tuijian'] = 0;
        }

        $data=D('Mobile/Article')->article_list($catid,$param);
        if($data['article_list']['list']){
            foreach ($data['article_list']['list'] as $k => $v){
                if($v['shop_id'] > 0)
                    $data['article_list']['list'][$k]['shop_name'] = idtoname ($v['shop_id'],'Shops');
                else
                $data['article_list']['list'][$k]['shop_name'] = '平台发布';
                $data['article_list']['list'][$k]['addtime_format']=time_format($v['addtime'],'Y-m-d');
                if(str_exists($v['thumb'],'http://')==false){
                    $data['article_list']['list'][$k]['thumb']='http://'.$_SERVER["HTTP_HOST"].$v['thumb'];
                }
            }
            $article_list=$data['article_list'];
            $return['data']['list']=$article_list;
            $return['status']=1;
        }else{
            $return['status']=2;
            $return['msg']='已加载全部数据';
        }
        
        // $catname=$data['catname'];
        $catname='头条';
        $return['data']['article_cat_list']=$article_cat_list;
        $return['data']['catname']=$catname;
        $return['data']['catid']=$catid;

        // $this ->assign('pid',I('pid'));
        $this->ajaxReturn($return);
    }
    /**
     *文章内容
     */
    public function article_cont() {
        $return=array('status'=>1);
        $id=I('id');
        $type=I('type');
        $data=D('Mobile/Article')->article_con($id,$type);
        $info=array();
        if($data['status']==0){
            if($data['content']){
                $data['content']['addtime']=time_format($data['content']['addtime']);
                $data['content']['content']=h($data['content']['content']);
            }
            $info['content']=$data['content'];
            $info['catname']=$data['catname'];
        }else{
            $return['status']=3;
            $return['msg']=$data['msg'];
            $this->ajaxReturn($return);
        }
        $return['data']=$info;
       $this->ajaxReturn($return);
    }
}