<?php
namespace DAO\Adv;

/**
 * User: liuyuzhen
 * Date: 2018/6/24
 * Time: 14:39
 * Description:
 */
class AdvMobileModel extends \DAO\AbstractModel{

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

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


    public function init(){

    }

    public function find($where,$field =\Our\NameConst::allField){
        $this->setDb($this->dbName);
        return $this->db->select($field)->from($this->_tableName)->where($where)->fetchOne();
    }


    public function getList($where,$field = \Our\NameConst::allField,$order=null){
        $this->setDb($this->dbName);
        $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;
    }

    public function deleteStoreAdvMobileCache($storeId){
        \Our\RedisHelper::delCachedFunction(\Redis\Db9\AdvMobileRedisModel::getInstance(),array(&$this, 'getList'),array(),array($storeId));
    }

    public function delAdvMobile($store){
        $advRedis = \Redis\Db9\AdvRedisModel::getInstance();
        $storeMiddleAdvsKey = \Our\NameConst::storeMiddleAdvsPrefix.$store;
        $advRedis->tableDel($storeMiddleAdvsKey);
    }
    /**
     * 类实例
     */
    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;
    }
}