<?php
/**
 * 文章
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author lss <lss@sina.cn>
 */
namespace Mobile\Model;
use Think\Model;
class ArticleModel extends Model{
    /**
      *帮助中心
      *@return array
      */
    public function help() {
        $where['status'] = 1;
        $where['pid'] = 0;
        $cat_list=M('ArticleCat')->where($where)->field(true)->order('sort desc,id desc')->select();
        $root['cat_info']=$cat_list;
        return $root;
    }
	/**
      *文章分类列表
      *@param $catid
      *@return array
      */
    public function article_cat_list() {
		$where = array();
		$where['status'] = 1;
		// $where['pid'] = 0;
    $where['pid'] = 1; //xyy 2019.1.19 
        $article_cat_list = M('ArticleCat')->where($where)->field('id,name,pid')->select();
        return $article_cat_list;
    }
    /**
      *文章列表
      *@param $catid
      *@return array
      */
    public function article_list($catid,$param=array()) {
        if($catid) {
            $catname=idtoname($catid,"ArticleCat",'name');
        }
        if(empty($catid)) {$catid=0; $catname='文章';}
        $article_list=article_list($catid,20,'',true,true,false,$param);
         if(!empty($article_list['list'])){
            foreach ($article_list['list'] as $k => $v){
                if(empty($k%5)){
                    $article_list['list'][$k]['is_big'] = 1;
                }
            }
        }
        $root['article_list']=$article_list;
        $root['catname']=$catname;
        return $root;
    }
    /**
       *文章内容
       *@param $id 文章ID,$type 文章类型
       *@return array
       */ 
    public function article_con($id,$type='') {
        $root=array();
        $root['status']=0;
        $root['msg']='';
        $root['url']='';
        if($id) {
            if ($type == 'gongg' || $type == '') {
                $map=array();
                $map['id']=$id;
                $catid = M('Article')->where($map)->getField('catid');
                $catname = idtoname($catid, "ArticleCat", 'name');
                $content = idtoname($id, "Article", 'content,title,addtime');
                $thumb=idtoname($id, "Article", 'thumb');
            }
            if ($type == 'goods') {
                $catname =str_cut(idtoname($id, "Goods", 'goods_name'),50);
                $content = idtoname($id, "GoodsContent", 'content,seotitle','goods_id',false);
            }
            $root['catname'] = $catname;
            $root['content'] = $content;
            $root['thumb'] = $thumb;
        }else{
            $root['url']=U("Index/index");
            $root['msg']="参数错误";
            $root['status']=1;
        }
        return $root;
    }
}