Brand.class.php 4.18 KB
<?php
/**
 * 品牌控制器
 */
class Controller_Admin_Brand extends Controller_Admin_Base 
{
    
    /**
     * 品牌列表Index
     */
    public function indexAction()
    {
        $state = $this->_request->query('state',1);
        $limit = 20 ;
        $total = Facade_Brand::getBrandTotal($state);
        $page = new Lib_Helper_Pagination($total,$limit);
        $offset = $page->getOffset() ;
        $info = Facade_Brand::getBrandByState($offset, $limit, $state);
        $relas = Facade_Brand::getBrandNewsRelaByBrandID(array_keys($info));
        $brandRelas = array();
        foreach($relas as $rela)
        {
            if(!isset($brandRelas[$rela['brand_id']]))
            {
               $brandRelas[$rela['brand_id']] = '';
            }
            $brandRelas[$rela['brand_id']] .= $rela['news_id'].',';
        }
        $page->setParames(array('state'=>$state));
        $this->_view['pagination'] = $page->getPagination();
        $this->_view['data'] = $info;
        $this->_view['brandRelas'] = $brandRelas;
        $this->_view['state']  = $state;
        $this->_view['key'] = Lib_Images::genKey('fragmentimg');
    }
    
    /**
     * 获取所有品牌
     *
     * @return json
     */
    public function getallbrandAction()
    {
    	$list = Facade_Brand::getBrandByState(0, 1000, 1);
    	$brands = array();
    	foreach ($list as $brand)
    	{
    		$index = Lib_Utils_StringHelper::getFirstLetter($brand['name']);
    		if(empty($index))
    		{
    			$index = substr($brand['name'], 0, 1);
    		}
    		if(is_numeric($index))
    		{
    			$index = '0-9';
    		}
    		$brands[$index][] = $brand;
    	}
    	ksort($brands);
    	return $this->returnJson(true,200, $brands);
    }
    
    /**
     * 获取品牌详情
     */
    public function detailAction()
    {
        $id = $this->_request->query('id',0);
        $info = Facade_Brand::getBrandbyID($id);
        if(info)
        {
            return $this->returnJson(true,200,info);
        }
        else
        {
            return $this->returnJson(false,404,null);
        }
    }
    
    /**
     * 编号
     */
    public function boothAction()
    {
    	$this->_view['boothList'] = Facade_Brand::getBoothList();
    }

    /**
     * 设置booth编号
     * 
     * @return json
     */
    public function setboothAction()
    {
    	$booth_id = $this->_request->query('booth_id', '');
    	$position = $this->_request->query('position', '');
    	$status = Facade_Brand::setBooth($booth_id, $position);
    	if($status)
    	{
    		return $this->returnJson(true, 200);
    	}
    	else
    	{
    		return $this->returnJson(false, 403);
    	}
    } 
    
    /**
     * 删除booth编号
     * 
     * @return json
     */
    public function delboothAction()
    {
    	$booth_id = $this->_request->query('booth_id', '');
    	$status = Facade_Brand::delBooth($booth_id);
    	if($status)
    	{
    		return $this->returnJson(true, 200);
    	}
    	else
    	{
    		return $this->returnJson(false, 403);
    	}
    }
    
    /**
     * 提交品牌
     */
    public function submitAction()
    {
        $id = $this->_request->query('id',0);
        $name = $this->_request->query('name','');
        $logo = $this->_request->query('logo','');
        $description = $this->_request->query('description','');
        $state = $this->_request->query('state','');
        $pics = $this->_request->query('pics','');
        $person = $this->_request->query('person','');
        $seq = $this->_request->query('seq','');
        $news_ids = $this->_request->query('news_ids','');
        $boothId = $this->_request->query('boothId', '');
        $link = $this->_request->query('link', '');
        $ret = false;
        if($id)
        {
            $ret = Facade_Brand::updateBrand($id, $name, $logo, $description, $state, $pics, $person, $seq, $news_ids, $boothId, $link);
        }
        else
        {
            $ret = Facade_Brand::submitBrand($name, $logo, $description, $state, $pics, $person, $seq, $news_ids, $boothId, $link);
        }
        
        if($ret)
        {
            return $this->returnJson(true,200,null);
        }
        else
        {
            return $this->returnJson(false,404,null);
        }
    }
}