Prod.class.php 5.19 KB
<?php

/**
 *  prod信息
 *
 * @name Service_Prod
 * @version 1.0 (2013-6-5)
 * @package Service/Prod
 * @author hbomb
 * @since 1.0
 */

class Service_Prod extends Lib_Service
{
    const ROUTER = 'prod.yohood.prod';
    private static $_tag = 'tag_yohood_prod_';
    private static $_key = 'key_yohood_prod_';
    /**
     * 获取prod
     * 
     * @param array|int $recom_status
     * @param int $offset
     * @param int $limit
     * @return array
     */
    public function getProd ($recom_status, $offset, $limit)
    {
    	if(is_array($recom_status))
    	{
    		$recom_status = implode(',', $recom_status);
    	}
    	$replaces = array('recom_status' => $recom_status);
        return self::service(self::ROUTER)->tag(self::$_tag)->fetchAssoc('getProd', array('offset' => $offset, 'limit' => $limit), $replaces);
    }
    
    
    /**
     * 根据brand_id获取prod
     * 
     * @param unknown_type $offset
     * @param unknown_type $limit
     * @param unknown_type $brand_id
     * @param int|array $recom_status
     * @return array
     */
    public function getProdByBrandId ($offset, $limit, $brand_id, $recom_status)
    {
    	if(is_array($recom_status))
    	{
    		$recom_status = implode(',', $recom_status);
    	}
    	$replaces = array('recom_status' => $recom_status);
        return self::service(self::ROUTER)->tag(self::$_tag)->fetchAssoc('getProdByBrandId', array('offset' => $offset, 'limit' => $limit, 'brand_id'=> $brand_id), $replaces);
    }
    
    /**
     * 根据brand_id获取prod总数
     *
     * @param string $brand_id
     * @param int|array $recom_status
     * @return array
     */
    public function getProdTotalByBrandId($brand_id, $recom_status)
    {
    	if(is_array($recom_status))
    	{
    		$recom_status = implode(',', $recom_status);
    	}
    	$replaces = array('recom_status' => $recom_status);
    	return self::service(self::ROUTER)->tag(self::$_tag)->fetchOne('getProdTotalByBrandId', array('brand_id'=> $brand_id), $replaces);
    }
    
    /**
     * 获取所有prod个数. 用于前端分页
     * 
     * @param array|int $recom_status
     * @return int
     */
    public function getProdTotal($recom_status)
    {
    	if(is_array($recom_status))
    	{
    		$recom_status = implode(',', $recom_status);
    	}
    	$replaces = array('recom_status' => $recom_status);
        return self::service(self::ROUTER)->tag(self::$_tag)->fetchOne('getProdTotal', array(), $replaces);
    }
    
    /**
     * 根据id更新prod操作.
     * @param string $name
     * @param string $brand_id
     * @param string $url
     * @param string $pic
     * @param string $text
     * @param string $create_time
     * @param int $price
     * @param int $recom_status
     * @param string $market_price
     * @param string $product_skn
     * @param string $product_id
     * @param int $id
     * @return boolean
     */
    public function updateProd ($name, $brand_id, $url, $pic, $text, $create_time, $price, $recom_status, $market_price, $product_skn, $product_id,  $id)
    {
        $param = array(
                	 'id'=>$id,
               		 'pic'=> $pic,
                	 'text'=>$text,
                	 'create_time'=>$create_time,
                	 'name'=>$name,
                	 'brand_id'=>$brand_id,
                	 'url'=>$url,
        		     'price' => $price,
        		     'recom_status'=> $recom_status,
        		     'market_price'=> $market_price,
        		     'product_skn'=> $product_skn,
        			 'product_id'=> $product_id
                );
        $status =  self::service(self::ROUTER)->cache(false)->update('updateProd', $param)->status();
        if($status)
        {
        	self::service(self::ROUTER)->delTags(self::$_tag);
        }
        return $status;
    }
    
    /**
     * 用户提交prod. 
     * 
     * @param string $name
     * @param string $brand_id
     * @param string $url
     * @param string $pic
     * @param string $text
     * @param string $create_time
     * @param int $price
     * @param int $recom_status
     * @param string $market_price
     * @param string $product_skn
     * @param string $product_id
     * @return int
     */
    public function submitProd ($name, $brand_id, $url, $pic, $text, $price, $recom_status, $market_price, $product_skn, $product_id)
    {
        $param = array(
                'pic'=> $pic,
                'text'=> $text,
                'name'=> $name,
                'brand_id'=> $brand_id,
                'url'=> $url,
        		'price' => $price,
        		'recom_status'=> $recom_status,
        		'market_price'=> $market_price,
        		'product_skn'=> $product_skn,
        		'product_id'=> $product_id
        );
        $status = self::service(self::ROUTER)->cache(false)->insert('insertProd', $param)->lastInsertId();
        if($status)
        {
        	self::service(self::ROUTER)->delTags(self::$_tag);
        }
        return $status;
    }
    
    /**
     * 删除prod
     * @param unknown_type $id
     */
    public function delProd($id)
    {
        $status = self::service(self::ROUTER)->cache(false)->delete('delProd',array('id'=>$id))->status();
        if($status)
        {
        	self::service(self::ROUTER)->delTags(self::$_tag);
        }
        return $status;
    }
}