<?php
namespace DAO\Article;
/**
 * User: liuyuzhen
 * Date: 2018/8/7
 * Time: 16:01
 * Description:
 */
class ArticleModel extends \DAO\AbstractModel{


    public function init(){

    }

    /**
     * 表名
     *
     * @var string
     */
    protected $_tableName = 'han_article';

    /**
     * 主键
     *
     * @var string
     */
    protected $_primaryKey = 'article_id';

    /**
     * 获取单条数据
     * @param $where
     * @return array
     */
    public function find($where,$field= \Our\NameConst::allField){
        $this->setDb($this->dbName);
        $data = $this->db->from($this->_tableName)->select($field)->where($where)->fetchOne();
        return $data;
    }

    public function findFromCache($where,$field= \Our\NameConst::allField){
        
    }

    public function getList($where,$field = \Our\NameConst::allField,$order = null){
        $this->setDb($this->dbName);
        if(is_array($where)){
            $where = $this->db->getSqlWhereByArray($where);
        }
        $this->db->select($field)->from($this->_tableName)->where($where);
        if($order){
            foreach($order as $key => $value){
                $this->db->order($key,$value);
            }
        }
        $result = $this->db->fetchAll();
        return $result;
    }

    /**
     * 类实例
     */
    private static $_instance = null;

    /**
     * 获取类实例
     */
    public static function getInstance($dbName=\Our\DbNameConst::salveDBConnectName) {
        if (!(self::$_instance instanceof self)) {
            self::$_instance = new self($dbName);
        }

        return self::$_instance;
    }
}