Prod.class.php 4.24 KB
<?php
/**
 * 产品控制器
 */
class Controller_Admin_Prod extends Controller_Admin_Base 
{
    
    /**
     * Prod列表Index
     */
    public function indexAction()
    {
        $limit = 20 ;
        $brand_id = intval($this->_request->query('brand_id', 0));
        $status = intval($this->_request->query('status', 0));
        $brand = array();
        $brands = array();
        if(!empty($brand_id))
        {
        	$brand = Facade_Brand::getBrandbyID($brand_id);
        	$total = Facade_Prod::getProdTotalByBrandId($brand_id);
        	$brands[$brand_id] = $brand;
        }
        else
        {
        	$total = Facade_Prod::getProdTotal($status);
        }
        $page = new Lib_Helper_Pagination($total, $limit);
        $page->setParames(array('brand_id'=> $brand_id,'status'=> $status));    
        $offset = $page->getOffset();
        if(!empty($brand_id))
        {
        	$info = Facade_Prod::getProdByBrandId($offset, $limit, $brand_id);
        }
        else
        {
        	$info = Facade_Prod::getProd($status, $offset, $limit);
        }
        foreach($info as $prod)
        {
        	if(!isset($brands[$prod['brand_id']]))
        	{
        		$brands[$prod['brand_id']] = Facade_Brand::getBrandbyID($prod['brand_id']);
        	}
        }
        $this->_view['pagination'] = $page->getPagination();
        $this->_view['data'] = $info;
        $this->_view['key'] = Lib_Images::genKey('fragmentimg');
        $this->_view['status'] = $status;
        $this->_view['brand'] = $brand;
        $this->_view['brand_id'] = $brand_id;
        $this->_view['brands'] = $brands;
    }
   
    
    /**
     * 提交prod
     */
    public function submitAction()
    {
        $id = $this->_request->query('id',0);
        $pic = $this->_request->query('pic','');
        $name = $this->_request->query('name','');
        $url = $this->_request->query('url','');
        $text = $this->_request->query('text','');
        $create_time = strtotime($this->_request->query('create_time', 0));
        $brand_id = $this->_request->query('brand_id',0); 
        $price = $this->_request->query('price', 0);
        $sort = $this->_request->query('sort', 0);
        $recom_status = $this->_request->query('recom_status', 0);
        $market_price = $this->_request->query('market_price', 0);
        $product_skn = $this->_request->query('product_skn', 0);
        $product_id = $this->_request->query('product_id', 0);
        $ret = false;
        if($id)
        {
            $ret = Facade_Prod::updateProd($name, $brand_id, $url, $pic, $text, $sort, $create_time, $price, $recom_status, $market_price, $product_skn, $product_id, $id);
        }
        else
        {
            $ret = Facade_Prod::submitProd($name, $brand_id, $url, $pic, $text, $sort, $price, $recom_status, $market_price, $product_skn, $product_id);
        }
        if($ret)
        {
            return $this->returnJson(true,200,null);
        }
        else
        {
            return $this->returnJson(false,404,null);
        }
    }
    
    /**
     * 删除
     */
    public function delAction()
    {
        $id = $this->_request->query('id',0);
        $ret = Facade_Prod::delProd($id);
        if($ret)
        {
            return $this->returnJson(true,200,null);
        }
        else
        {
            return $this->returnJson(false,404,null);
        }
    }
    public function getprodAction()
    {
        $url = 'http://v5.open.yohobuy.com/?open_key=c4ca4238a0b923820dcc509a6f75849b&method=yh.product.getByUrl&product_url=';
        $prodUrl = $this->_request->query('url','');
        if($prodUrl)
        {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url.$prodUrl);
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
            $result = curl_exec($ch);
            curl_close($ch);
            $ret = json_decode($result,true);
            if($ret['code'] == 200)
            {
                return $this->returnJson(true,200,$ret['data']);
            }
            else
            {
                return $this->returnJson(true,404,null,'链接有问题');
            }
        }
        else
        {
            return $this->returnJson(false,404,null,'获链接有问题');
        }

    }
}