Onlinereg.class.php 9.42 KB
<?php
class Controller_Admin_Onlinereg extends Controller_Admin_Base
{
    /**
     * 参展商登记
     */
    public function indexAction()
    {
        $type = intval($this->_request->get('type', 0));
        $types = array(
                    Facade_Onlinereg::TYPE_ONLINE_EXHIBITOR =>'参展商',
                    Facade_Onlinereg::TYPE_ONLINE_SPONSOR =>'赞助商',
                    Facade_Onlinereg::TYPE_ONLINE_MEDIA =>'媒体');
        if(!in_array($type, array_keys($types))) {
            $type = 0;
        }
        $limit = 15;
        $total = Facade_Onlinereg::getSellerTotalByType($type);
        $pagination = new Lib_Helper_Pagination($total, $limit);
        $pagination->setParames(array('type' => $type));
        $list = Facade_Onlinereg::getSellerListByType($type, $pagination->getOffset(), $limit);
        $this->_view['list'] = $list;
        $this->_view['pagination'] = $pagination->getPagination();
        $this->_view['type'] = $type;
        $this->_view['sellerTypes'] = $types;
          
    }
    
    /**
     * 参展商手册
     */
    public function downloadAction()
    {
        $limit = 15;
        $type = intval($this->_request->get('type', 0));
        if(!in_array($type, array(Facade_Onlinereg::TYPE_ONLINE_DOWNLOAD_EXHIBITOR, 
            Facade_Onlinereg::TYPE_ONLINE_DOWNLOAD_MEDIA))) 
        {
            $type = 0;
        }
        $total = Facade_Onlinereg::getDownloadTotalByType($type);
        $pagination = new Lib_Helper_Pagination($total, $limit);
        $list = Facade_Onlinereg::getDownloadListByType($type, $pagination->getOffset(), $limit);
        foreach ($list as &$download)
        {
            $download['cover'] = Lib_Images::getImageUrl($download['cover'], 'source','fragmentimg');
        }
        $this->_view['type'] = $type;
        $this->_view['list'] = $list;
        $this->_view['pagination'] = $pagination->getPagination();
        $this->_view['key'] = Lib_Images::genKey('fragmentimg');
    }
    
    /**
     * 获取商家数据
     * 
     * @return array
     */
    public function getsellerAction()
    {
        $sellerId = $this->_request->query('id');
        $seller = array();
        if(!empty($sellerId)) 
        {
            $seller = Facade_Onlinereg::getSellerById($sellerId);
        }
        if(!empty($seller))
        {
            return $this->returnJson(true, 200, $seller);
        }
        else
        {
            return $this->returnJson(false, 403);
        }
    }
    
    /**
     * 设置商家数据
     * 
     * @return array
     */
    public function setsellerAction()
    {
        $data = $_POST;
        if(isset($data['id']))
        {
            unset($data['files']);
            $data = array_map('addslashes', $data);
            $status = Facade_Onlinereg::setSeller($data);
            if($status)
            {
                return $this->returnJson(true, 200);
            }
            else
            {
                return $this->returnJson(false, 403);
            }
        }
        else
        {
            return $this->returnJson(false, 403);
        }
    }
    
    /**
     * 获取下载相关
     */
    public function getdownloadAction()
    {
        $id = intval($this->_request->query('id'));
        $download = Facade_Onlinereg::getDownloadById($id);
        return $this->returnJson(true, 200, $download);
    }
    
    /**
     * 设置下载信息
     * 
     * @return json
     */
    public function setdownloadAction()
    {
        $status = false;
        $type = $this->_request->query('type', 0);
        $id = $this->_request->query('id', 0);
        $title = trim($this->_request->query('title', ''));
        $cover = $this->_request->query('cover', '');
        $file = $this->_request->query('file', '');
        $source = $this->_request->query('source', '');
        $source_link = $this->_request->query('source_link', '');
        if(!empty($title) && !empty($id))
        {
           //更新数据
           $status = Facade_Onlinereg::setDownloadInfoById($id, $title, $cover, $file, $source, $source_link); 
        }
        else if(!empty($title) && in_array($type, array(
            Facade_Onlinereg::TYPE_ONLINE_DOWNLOAD_EXHIBITOR,
            Facade_Onlinereg::TYPE_ONLINE_DOWNLOAD_MEDIA)))    
        {
            $status = Facade_Onlinereg::setDownloadInfo($title, $cover, $file, $source, $source_link, $type);
        }
        if($status)
        {
            return $this->returnJson(true, 200);
        }
        else
        {
            return $this->returnJson(false, 403);
        }
    }
    
    /**
     * 删除下载数据
     * 
     */
    public function deldownloadAction()
    {
        $id = $this->_request->query('id');
        $status = Facade_Onlinereg::delDownload($id);
        if($status)
        {
            return $this->returnJson(true, 200);
        }
        else
        {
            return $this->returnJson(false, 403);
        }
    }
    
    /**
     * 导出excel
     */
    public function exportAction()
    {
        $typeAttrs = array(
            Facade_Onlinereg::TYPE_ONLINE_EXHIBITOR => array('ID','品牌名称','是否入驻有货','品牌注册','公司名称','联系人',
                '电话','邮箱','公司与品牌关系','商品所在地','是否3C','官网','时间'),
            Facade_Onlinereg::TYPE_ONLINE_SPONSOR => array('ID','品牌名称','是否入驻有货','产品类型','所属国家','公司名称','公司地址',
                '联系人','电话','邮箱','品牌官网','时间'),
            Facade_Onlinereg::TYPE_ONLINE_MEDIA => array('ID','姓名','职位','性别','媒体名/公司名','介绍','官网地址',
                '所在城市','邮箱','手机','座机','固定地址','邮编','时间'),
        );
        $typeDBKeys = array(
            Facade_Onlinereg::TYPE_ONLINE_EXHIBITOR => array('id','name','is_enter_yohobuy',
            'brand_reg_type','company','contact','telphone','email','relation','place','is_3c','website','create_time'),
            Facade_Onlinereg::TYPE_ONLINE_SPONSOR => array('id','name','is_enter_yohobuy','product_type','country',
            'company','place','contact','telphone','email','website','create_time'),
            Facade_Onlinereg::TYPE_ONLINE_MEDIA => array('id','name','profession','sex','company','introduction','website',
                'city','email','mobile','telphone','place','zipcode','create_time'),
        );
        $typeSaveNames = array(
            Facade_Onlinereg::TYPE_ONLINE_EXHIBITOR => 'exhibitor',
            Facade_Onlinereg::TYPE_ONLINE_SPONSOR => 'sponsor',
            Facade_Onlinereg::TYPE_ONLINE_MEDIA => 'media',
        );
        $type = 0;
        $id = $this->_request->query('id');
        $sellerIds = array_filter(explode(',', $id),'is_numeric');
        $sellerList = array();
        foreach($sellerIds as $sellerId) 
        {
            $sellerList[] = Facade_Onlinereg::getSellerById($sellerId);
        }
        if(!empty($sellerList)) 
        {
            $excel = new Util_Excel_Excel();
            $excel->getProperties()->setCreator('yoho')
            ->setTitle('yohood')->setSubject('yohood')->setDescription('yohood')->setKeywords('yohood');
            $excel->setActiveSheetIndex(0);
            $type = $sellerList[0]['type'];
            $attrs = $typeAttrs[$type];
            $indexs = range('A','Z');
            $brandRegTypes = array('未注册','已注册','已申请');
            $relationAttrs = array('品牌商','代理商','经销商','其他');
            $pos = 0;
            $cellNum = 1;
            foreach($attrs as $attr)//输出属性
            {
                $cell = $indexs[$pos++];
                $excel->getActiveSheet()->getColumnDimension($cell)->setWidth(15);
                $excel->getActiveSheet()->setCellValue($cell.$cellNum, $attr);
            }
            foreach($sellerList as $seller) 
            {
                $cellNum ++;
                $pos = 0;
                for($i = 0; $i<count($attrs); $i++)
                {
                    $key = $typeDBKeys[$type][$i];
                    $cell = $indexs[$pos++].$cellNum;
                    $attr = $seller[$key];
                    if($key == 'create_time') //时间属性
                    {
                        $value = date('Y-m-d H:i:s', $attr);
                    }
                    else if(in_array($key, array('is_enter_yohobuy','is_3c')))//是否
                    {
                        $value = empty($attr) ? '否':'是';
                    }
                    else if($key == 'brand_reg_type')//品牌注册类型
                    {
                        $value = $brandRegTypes[$attr];
                    }
                    else if($key == 'relation')//公司与品牌关系
                    {
                        $value = $relationAttrs[$attr];
                    }
                    else 
                    {
                        $value = $attr;
                    }
                    $excel->getActiveSheet()->setCellValue($cell, $value);
                }
            }
            header('Content-Type: application/vnd.ms-excel');
            header('Content-Disposition: attachment;filename="'.$typeSaveNames[$type].'.xls"');
            header('Cache-Control: max-age=0');
            $excel->setActiveSheetIndex(0);
            $objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
            $objWriter->save('php://output');
        }
        else 
        {
            die('没有下载');
        }
    }
}