Brand.class.php 8.22 KB
<?php

/**
 *  品牌信息
 *
 * @name Service_Brand
 * @version 1.0 (2013-6-5)
 * @package Service/Brand/Brand
 * @author hbomb
 * @since 1.0
 */

class Service_Brand extends Lib_Service
{
    const ROUTER = 'brand.yohood.brand';
    private static $_tag = 'tag_yohood_brand_';
    private static $_key = 'key_yohood_brand_';
    private static $_rela_tag = 'key_yohood_brand_news_';
    /**
     * 获取品牌
     * 
     * @param unknown_type $offset
     * @param unknown_type $limit
     * @param unknown_type $status
     * @return Ambigous <multitype:, Util_Dao_Db_PdoQuery>
     */
    public function getBrandByState ($offset, $limit, $state)
    {
        return self::service(self::ROUTER)->tag(self::$_tag)->
            fetchAssoc('getBrandByState', array('offset' => $offset, 'limit' => $limit, 'state'=>$state));
    }
    
    /**
     * 根据状态获取所有品牌个数. 用于前端分页
     * 
     * @param $status
     */
    public function getBrandTotal ($state)
    {
        return self::service(self::ROUTER)->tag(self::$_tag)->fetchOne('getBrandTotal', array('state'=>$state));
    }
    
    /**
     * 根据id更新品牌状态. 用于管理员更新一个品牌的操作.
     * @param string $id
     * @param string $name
     * @param string $logo
     * @param string $description
     * @param string $state
     * @param string $pics
     * @param string $person
     * @param string $seq
     * @param int $boothId
     * @params string $link
     * @return boolean
     */
    public function updateBrand ($id, $name,$logo,$description,$state,$pics,$person,$seq,$news_ids, $boothId, $link)
    {
        $param = array(
	                'id'=> $id,
	                'name'=> $name,
	                'logo'=> $logo,
	                'description'=> $description,
	                'state'=> $state,
	                'pics'=> $pics,
	                'person'=> $person,
	                'seq'=> $seq,
	                'news_ids'=> $news_ids,
	        		'booth_id'=> $boothId,
        		 	'link' => $link
               );
        $status = self::service(self::ROUTER)->cache(false)->update('updateBrand', $param)->status();
        if($status)
        {
        	self::service(self::ROUTER)->delTags(self::$_tag);
        }
        return $status;
    }
    
    /**
     * 用户提交品牌. 
     * @param string $name
     * @param string $logo
     * @param string $description
     * @param string $pics
     * @param string $person
     * @param string $news_ids
     * @param string $seq
     * @param string $state
     * @param int $boothId
     * @param string $link
     * @return int
     */
    public function submitBrand ($name, $logo, $description, $pics, $person, $news_ids, $seq, $state, $boothId, $link)
    {
        $param = array(
                'name'=> $name,
                'logo'=>$logo,
                'description'=>$description,
                'state'=>$state,
                'pics'=>$pics,
                'person'=>$person,
                'seq'=>$seq,
                'news_ids'=>$news_ids,
        		'booth_id'=> $boothId,
        		'link' => $link
        );
        $status = self::service(self::ROUTER)->cache(false)->insert('insertBrand', $param)->lastInsertId();
        if($status)
        {
        	self::service(self::ROUTER)->delTags(self::$_tag);
        }
        return $status;
    }
    
    /**
     * 根据ID获取品牌
     * 
     * @param string $id
     * @return array
     */
    public function getBrandByID($id)
    {
        return self::service(self::ROUTER)->tag(self::$_tag)->fetchRow('getBrandByID', array('id'=>$id));
    }
    
    /**
     * 设置booth 
     * 
     * @param string $booth_id
     * @param string $position
     * @return boolean
     */
    public function setBooth($booth_id, $position)
    {
    	$params = array('booth_id' => $booth_id, 'position' => $position);
    	$status = self::service(self::ROUTER)->cache(false)->insert('setBooth', $params)->status();
    	if($status)
    	{
    		self::service(self::ROUTER)->delTags(self::$_tag);
    	}
    	return $status;
    }
    
    /**
     * 获取booth
     * 
     * @return array
     */
    public function getBoothList()
    {
    	return self::service(self::ROUTER)->tag(self::$_tag)->fetchAssoc('getBoothList');
    }
    
    /**
     * 删除booth
     *
     * @return bolean
     */ 
    public function delBooth($booth_id)
    {
    	$status =  self::service(self::ROUTER)->cache(false)->delete('delBooth', array('booth_id'=> $booth_id))->status();
    	if($status)
    	{
    		self::service(self::ROUTER)->delTags(self::$_tag);
    	}
    	return $status;
    }
    
    /**
     * 获取签到布局列表
     * 
     * @return array
     */
    public function getSignLayoutList()
    {
    	return self::service(self::ROUTER)->tag(self::$_tag)->fetchAssoc('getSignLayoutList');
    }
    
    /**
     * 获取签到图片
     * 
     * @return array
     */
    public function getSignPicList()
    {
    	return self::service(self::ROUTER)->tag(self::$_tag)->fetchAssoc('getSignPicList');
    }
    
    /**
     * 获取签到坐标
     * 
     * @return array
     */
    public function getSignPosition()
    {
    	return self::service(self::ROUTER)->tag(self::$_tag)->fetchAll('getSignPosition');
    }
    
    /**
     * 获取有货品牌
     * 
     * @return array
     */
    public function getYohobuyBrand()
    {
    	return self::service(self::ROUTER)->tag(self::$_tag)->fetchAssoc('getYohobuyBrand');
    }
    
    /**
     * 获取签到品牌
     * 
     * @return array
     */
    public function getSignBrand()
    {
    	return self::service(self::ROUTER)->tag(self::$_tag)->fetchAll('getSignBrand');
    }
    
    /**
     * 获取所有品牌
     * 
     * @return array
     */
    public function getBrand()
    {
    	return self::service(self::ROUTER)->tag(self::$_tag)->fetchAssoc('getBrand');
    }
    
    /**
     * 设置品牌和资讯对应关系
     *
     * @param int $news_id
     * @param int $brand_id
     * @return boolean
     */
    public  function setBrandNewsRela($news_id, $brand_id)
    {
    	return self::service(self::ROUTER)->tag(self::$_rela_tag)->insert('setBrandNewsRela', 
    	   array('news_id' => intval($news_id), 'brand_id'=> intval($brand_id)))->status();
    }
    
    /**
     * 根据news_id获取品牌和资讯对应关系
     *
     * @param int|array $news_id
     * @return array
     */
    public function getBrandNewsRelaByNewsID($news_id)
    {
        if(is_numeric($news_id))
        {
        	$news_id = array($news_id);
        }
        return self::service(self::ROUTER)->tag(self::$_rela_tag)->fetchAssoc('getBrandNewsRelaByNewsID', array(), array('news_id' => implode(',', $news_id)));
    } 
    
    /**
     * 根据news_id获取品牌和资讯对应关系
     *
     * @param int|array $brand_id
     * @return array
     */
    public function getBrandNewsRelaByBrandID($brand_id)
    {
        if(empty($brand_id))
        {
        	return array();
        }
        if(is_numeric($brand_id))
        {
            $brand_id = array($brand_id);
        }
        return self::service(self::ROUTER)->tag(self::$_rela_tag)->fetchAssoc('getBrandNewsRelaByBrandID', array(), array('brand_id' => implode(',', $brand_id)));
    }
    
    /**
     * 根据news_id删除品牌和资讯对应关系
     *
     * @param int $news_id
     * @return array
     */
    public  function deleteBrandNewsRelaByNewsID($news_id)
    {
        return self::service(self::ROUTER)->tag(self::$_rela_tag)->delete('deleteBrandNewsRelaByNewsID', array('news_id' => intval($news_id)));
    }
    
    /**
     * 获取相同的news_ids
     * 
     * @param int $news_id
     * @return array
     */
    public function getSameNewsByNewsID($news_id)
    {
        return self::service(self::ROUTER)->tag(self::$_rela_tag)->fetchCol('getSameNewsByNewsID', array('news_id' => intval($news_id)));
    }
    
    /**
     * 根据名称获取品牌列表
     *
     * @param string $name
     * @param int $state
     * @return array
     */
    public function getBrandByName($name, $state)
    {
        $name = strip_tags($name);
        $name = '%'.addslashes($name).'%';
        return self::service(self::ROUTER)->tag(self::$_tag)->fetchAssoc('getBrandByName', 
          array('state'=> $state,'name'=> $name));
    }  
}