<?php
/**
 * 手机专题
 *
 *
 *
 *
 */



defined('InShopNC') or exit('Access Invalid!');

require_once (BASE_ROOT_PATH . '/helper/util_helper.php');
require_once (BASE_ROOT_PATH . '/helper/special/block_filter.php');
require_once (BASE_ROOT_PATH . '/helper/special/upgrade_helper.php');
require_once (BASE_ROOT_PATH . '/helper/search/tcp_client.php');
require_once (BASE_ROOT_PATH . '/helper/search/util.php');
require_once (BASE_ROOT_PATH . '/helper/search_param.php');
require_once (BASE_ROOT_PATH . '/helper/area_helper.php');
require_once (BASE_ROOT_PATH . '/helper/model_helper.php');
require_once (BASE_ROOT_PATH . '/helper/ugc_helper.php');
require_once (BASE_ROOT_PATH . '/helper/activity_helper.php');

class mb_specialControl extends SystemControl
{
    const mb_home_tab_id = 123;
    const def_item_bg_color     = '#F7F7F7';
    const def_item_bg_type      = 'color';
    const def_divider_bg_img    = '/mobile/defimg/divider_bg.png';

	public function __construct()
    {
		parent::__construct();
	}

    public function area_uplastOp()
    {
        echo "area_uplast start";
        area_helper::uplast_country();
        echo "area_uplast end";

    }
    public function area_fixareaidOp()
    {
        echo "area_fixareaid start";
        area_helper::fix_areaid();
        echo "area_fixareaid end";
    }
    public function area_fixareainfoOp()
    {
        echo "fix_areainfo start";
        area_helper::fix_areainfo();
        echo "fix_areainfo end";

    }

	//升级专题数据
    public function upgradeOp()
    {
        $mod_mb_special = Model('mb_special');
        //$items = Model()->table('mb_special_item')->where(array('item_type' => 'home7','special_id' => array('gt',10)))->order('special_id desc')->field('*')->limit(2)->select();

        $items = Model()->table('mb_special_item')->field('*')->limit(false)->select();
        foreach ($items as $item)
        {
            $filter = new upgrade_helper($item['item_type'],$item['special_id'],unserialize($item['item_data']));
            $item_data = $filter->filter();
            if($item_data == false) continue;
            $result = $mod_mb_special->editMbSpecialItemByID(array('item_data' => $item_data), $item['item_id'], $item['special_id']);
            if($result == false) {
                echo "upgrade error special_id={$item['special_id']} item_id={$item['item_id']}</br>";
            } else {
                echo "upgrade success special_id={$item['special_id']} item_id={$item['item_id']}</br>";
            }
        }
    }
    /**
     * 专题列表
     */
    public function special_listOp()
    {
        $special_id = intval($_REQUEST['search_special_id']);
        $special_desc = trim($_REQUEST['special_desc']);

        if($special_id > 0) {
            $cond = array("special_id" => $special_id);
        }
        elseif(!empty($special_desc)) {
            $cond = array("special_desc" => array('like', "%{$special_desc}%"));
        } else {
            $cond = [];
        }
        $cond['from_user'] = 0;

        $model_mb_special = Model('mb_special');
        $mb_special_list = $model_mb_special->getMbSpecialList($cond, 50);

        Tpl::output('list', $mb_special_list);
        Tpl::output('page', $model_mb_special->showpage(2));

        $this->show_menu('special_list');
        Tpl::showpage('mb_special.list');
    }

    public function discoveryOp()
    {
        $special_id = intval($_REQUEST['search_special_id']);
        $special_desc = trim($_REQUEST['special_desc']);

        if($special_id > 0) {
            $cond = array("special_id" => $special_id);
        }
        elseif(!empty($special_desc)) {
            $cond = array("special_desc" => array('like', "%{$special_desc}%"));
        } else {
            $cond = [];
        }
        $cond['from_user'] = 0;

        $model_mb_special = Model('mb_special');
        $mb_special_list = $model_mb_special->getMbSpecialList(['from_user' => 1,'special_id' => ['gt', 0],'state' => 0,'reader_type' => 0], 50);

        Tpl::output('list', $mb_special_list);
        Tpl::output('page', $model_mb_special->showpage(2));

        $this->show_menu('special_list');
        Tpl::showpage('mb_special.list');
    }

    public function search_keyword_coverOp()
    {
        $cover_img = trim($_POST['cover_img']);
        $keywords  = trim($_POST['keyword']);
        $special_id = intval($_POST['special_id']);

        if($special_id > 0 && !empty($keywords))
        {
            $mod_special = Model('mb_special');
            $mod_special->editMbSpecial(['keywords' => $keywords,'share_image' =>$cover_img],$special_id);
            echo json_encode(200);
        } else {
            echo json_encode(-1);
        }
    }

    public function tab_listOp()
    {
        $mod_webcode = Model('web_code');
        $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
        $this->show_menu('tab_list');
        Tpl::output('tabs', $tabs);
        Tpl::showpage('mb_special.tab');
    }

    /**
     * 保存专题
     */
    public function special_saveOp()
    {
        $model_mb_special = Model('mb_special');

        $param = array();
        $param['special_desc'] = $_POST['special_desc'];
        $result = $model_mb_special->addMbSpecial($param);

        if($result) {
            $this->log('添加手机专题' . '[ID:' . $result. ']', 1);
            showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'special_list'));
        } else {
            $this->log('添加手机专题' . '[ID:' . $result. ']', 0);
            showMessage(L('nc_common_save_fail'), urlAdmin('mb_special', 'special_list'));
        }
    }

    /**
     * 编辑专题描述 
     */
    public function update_special_descOp() {
        $model_mb_special = Model('mb_special');

        $param = array();
        $param['special_desc'] = $_GET['value'];
        $result = $model_mb_special->editMbSpecial($param, $_GET['id']);

        $data = array();
        if($result) {
            $this->log('保存手机专题' . '[ID:' . $result. ']', 1);
            $data['result'] = true;
        } else {
            $this->log('保存手机专题' . '[ID:' . $result. ']', 0);
            $data['result'] = false;
            $data['message'] = '保存失败';
        }
        echo json_encode($data);die;
    }

    /**
     * 删除专题
     */
    public function special_delOp()
    {
        $model_mb_special = Model('mb_special');

        $result = $model_mb_special->delMbSpecialByID($_POST['special_id']);
        if($result) {
            $this->log('删除手机专题' . '[ID:' . $_POST['special_id'] . ']', 1);
            showMessage(L('nc_common_del_succ'), urlAdmin('mb_special', 'special_list'));
        } else {
            $this->log('删除手机专题' . '[ID:' . $_POST['special_id'] . ']', 0);
            showMessage(L('nc_common_del_fail'), urlAdmin('mb_special', 'special_list'));
        }
    }

    /**
     * 编辑首页
     */
    public function index_editOp()
    {
        $model_mb_special = Model('mb_special');
        $special_item_list = $model_mb_special->getMbSpecialItemListByID($model_mb_special::INDEX_SPECIAL_ID);
        Tpl::output('list', $special_item_list);
        Tpl::output('page', $model_mb_special->showpage(2));
        Tpl::output('module_list', $model_mb_special->getMbSpecialModuleList());
        Tpl::output('special_id', $model_mb_special::INDEX_SPECIAL_ID);
        $this->show_menu('index_edit');

        Tpl::showpage('mb_special_item.list');
    }

    /**
     * 编辑专题
     */
    public function special_editOp() {
        
        $model_mb_special = Model('mb_special');
        $special_item_list = $model_mb_special->getMbSpecialItemListByID($_GET['special_id']);
        $spinfo = $model_mb_special->getMbSpecialByID($_GET['special_id']);
        $tabs = empty($spinfo['tabs']) ? "" : $spinfo['tabs'];

        Tpl::output('list', $special_item_list);
        Tpl::output('tabs', $tabs);

        Tpl::output('page', $model_mb_special->showpage(2));

        Tpl::output('module_list', $model_mb_special->getMbSpecialModuleList());
        Tpl::output('special_id', $_GET['special_id']);

        $this->show_menu('special_item_list');
        Tpl::showpage('mb_special_item.list');
    }

    /**
     * 专题项目添加
     */
    public function special_item_addOp()
    {
        $item_info = $this->add_item($_POST['special_id'],$_POST['item_type']);
        if($item_info) {
            echo json_encode($item_info);die;
        } else {
            echo json_encode(array('error' => '添加失败'));die;
        }
    }

    private function add_item($special_id,$item_type)
    {
        $model_mb_special = Model('mb_special');

        $param = array();
        $param['special_id'] = $special_id;
        $param['item_type'] = $item_type;
        $param['bg_type'] = self::def_item_bg_type;
        $param['bg_data'] = self::def_item_bg_color;
        $param['has_margin'] = 0;
        $param['bg_image'] = '';

        if($item_type == 'divider')
        {
            $filter = new block_filter($item_type,$special_id,null);
            $image = RESOURCE_SITE_URL . self::def_divider_bg_img;
            if($filter->to_local($image)) {
                $param['bg_image'] = $image;
            }
        }

        $item_info = $model_mb_special->addMbSpecialItem($param);
        return $item_info;
    }

    //专题项目插入分割线
    public function add_frontOp()
    {
        $item_type = $_POST['item_type'];
        $special_id  = intval($_POST['special_id']);
        $item_info = $this->add_item($special_id,$item_type);
        if($item_info == false) {
            echo json_encode(array('error' => '添加失败'));die;
        }

        $sel_item_id = intval($_POST['sel_item_id']);
        $insert_item_id = intval($item_info['item_id']);

        $model_mb_special = Model('mb_special');
        $special_item_list = $model_mb_special->getMbSpecialItemListByID($special_id);

        $item_ids = [];
        foreach ($special_item_list as $item)
        {
            $item_id = intval($item['item_id']);
            if($item_id == $sel_item_id) {
                $item_ids[] = $insert_item_id;
                $item_ids[] = $item_id;
            }
            elseif($item_id == $insert_item_id) {
                continue;
            }
            else {
                $item_ids[] = $item_id;
            }
        }

        $index = 0;
        foreach ($item_ids as $item_id) {
            $result = $model_mb_special->editMbSpecialItemByID(array('item_sort' => $index), $item_id, $special_id);
            $index++;
        }

        $data = array();
        $data['message'] = '操作成功';
        echo json_encode($data);
     }

     public function move_itemOp()
     {
         $special_id  = intval($_POST['special_id']);
         $src_id = intval($_POST['src_id']);
         $desc_id = intval($_POST['dest_id']);

         $href = urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id']));

         if($src_id == $desc_id || $src_id <= 0 || $desc_id <= 0) {
             showMessage(L('nc_common_save_fail'), $href);
         }
         else
         {
             $model_mb_special = Model('mb_special');
             $special_item_list = $model_mb_special->getMbSpecialItemListByID($special_id);

             $nfind = 0;
             $item_ids = [];
             foreach ($special_item_list as $item)
             {
                 $item_id = intval($item['item_id']);
                 if($item_id == $desc_id) {
                     $item_ids[] = $src_id;
                     $item_ids[] = $desc_id;
                     $nfind += 1;
                 }
                 elseif($item_id == $src_id) {
                     $nfind += 1;
                     continue;
                 }
                 else {
                     $item_ids[] = $item_id;
                 }
             }
             if($nfind == 2)
             {
                 $index = 0;
                 foreach ($item_ids as $item_id) {
                     $result = $model_mb_special->editMbSpecialItemByID(array('item_sort' => $index), $item_id, $special_id);
                     $index++;
                 }
                 showMessage(L('nc_common_save_succ'),$href);
             }
             else {
                 showMessage(L('nc_common_save_fail'), $href);
             }
         }
     }

     public function special_item_edit_tabOp()
     {
         $href = urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id']));

         $special_id  = intval($_POST['special_id']);
         $tabs  = $_POST['tabs'];
         if($special_id > 0)
         {
             if(!empty($tabs))
             {
                 $items = preg_split("/#/",$tabs);
                 foreach ($items as $item)
                 {
                     $values = explode(":",$item);
                     if(count($values) != 2 || intval($values[0]) <= 0) {
                         showMessage(L('nc_common_save_fail'), $href);
                         return;
                     }
                 }
             }

             $mod_special = Model('mb_special');
             $mod_special->editMbSpecial(['tabs' => $tabs],$special_id);
             showMessage(L('nc_common_save_succ'),$href);
         } else {
             showMessage(L('nc_common_save_fail'), $href);
         }
     }

    /**
     * 专题项目删除
     */
    public function special_item_delOp() {
        $model_mb_special = Model('mb_special');

        $condition = array();
        $condition['item_id'] = $_POST['item_id'];

        $result = $model_mb_special->delMbSpecialItem($condition, $_POST['special_id']);
        if($result) {
            echo json_encode(array('message' => '删除成功'));die;
        } else {
            echo json_encode(array('error' => '删除失败'));die;
        }
    }

    /**
     * 专题项目编辑
     */
    public function special_item_editOp()
    {
        $model_mb_special = Model('mb_special');
        $item_info = $model_mb_special->getMbSpecialItemInfoByID($_GET['item_id']);

        if($item_info['has_margin'] == 1) {
            $item_info['has_margin'] = 'true';
        } else {
            $item_info['has_margin'] = 'false';
        }

        Tpl::output('item_info', $item_info);

        if($item_info['special_id'] == 0) {
            $this->show_menu('index_edit');
        } else {
            $this->show_menu('special_item_list');
        }
        Tpl::showpage('mb_special_item.edit');
    }

    /**
     * 专题项目保存
     */
    public function special_item_saveOp()
    {
        $model_mb_special = Model('mb_special');

        $bg_type = $_POST['bg_type'];
        if($bg_type == 'image') {
            $bg_data = $_POST['bg_image_name'];
        } else {
            $bg_data = $_POST['bg_data'];
            if(empty($bg_data)) $bg_data = self::def_item_bg_color;
        }

        if($_POST['has_margin'] == "true") {
            $has_margin = 1;
        } else {
            $has_margin = 0;
        }

        $filter = new block_filter($_POST['item_type'],$_POST['special_id'],$_POST['item_data']);
        $item_data = $filter->filter();

        if($item_data == false) $item_data = $_POST['item_data'];
        $updata = array('item_data' => $item_data,'bg_type' => $bg_type,'bg_data' => $bg_data,'bg_image' => $_POST['bg_image_name'],'has_margin' => $has_margin);
        $result = $model_mb_special->editMbSpecialItemByID($updata, $_POST['item_id'], $_POST['special_id']);

        if($result)
        {
            if($_POST['special_id'] == $model_mb_special::INDEX_SPECIAL_ID) {
                showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'index_edit'));
            }
            else
            {
                $ret = $this->other_check($_POST['special_id'],$err);
                if($ret) {
                    showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id'])));
                } else {
                    showMessage($err, urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id'])));
                }
            }
        } else {
            showMessage(L('nc_common_save_succ'), '');
        }
    }
    private function other_check($special_id,&$err)
    {
        $special_id = intval($special_id);

        global $config;
        $opids = $config['optional_goods'];
        if(in_array($special_id,$opids))
        {
            $layerror = \activity\optional_goods::instance()->layout_error();
            if($layerror != false) {
                $gids = implode(",",$layerror);
                $err = "下列商品 {$gids} 布局错误或者重复添加";
                return false;
            }

            $all_goods = activity\optional_goods::instance()->all_goods();
            $err_goods = [];
            foreach ($all_goods as $gid)
            {
                $ret = activity_helper::optional_goods_check($gid,$erret);
                if($ret == false) {
                    $err_goods[] = $gid;
                }
            }

            if(!empty($err_goods)) {
                $gids = implode(",",$err_goods);
                $err = "下列商品 {$gids} 已经参与了其它活动，不能添加，请处理";
                return false;
            }
            return true;
        }
        else {
            return true;
        }
    }

    /**
     * 图片上传
     */
    public function special_image_uploadOp()
    {
        $data = array();
        if(!empty($_FILES['special_image']['name'])) {
            $prefix = 's' . $_POST['special_id'];
            $upload	= new UploadFile();
            $upload->set('default_dir', ATTACH_MOBILE . DS . 'special' . DS . $prefix);
            $upload->set('fprefix', $prefix);
            $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));

            $result = $upload->upfile('special_image');
            if(!$result) {
                $data['error'] = $upload->error;
            }
            $data['image_name'] = $upload->file_name;
            $data['image_url'] = getMbSpecialImageUrl($data['image_name']);
        }
        echo json_encode($data);
    }

    /**
     * 商品列表
     */
    public function goods_listOp()
    {
        $p['keyword'] = urlencode($_REQUEST['keyword']);
        $param = new search_param($p);
        $params = $param->format();
        $result = search\search_client::instance()->get_result($params);
        $model_goods = Model('goods');
        $goods_list = $model_goods->getGoodsListByColorDistinct(array('goods_commonid' => array('in',$result['cids'])),
            'goods_id,goods_name,goods_promotion_price,goods_image,goods_storage', '', 10);

        Tpl::output('goods_list', $goods_list);
        Tpl::output('keyword', $_REQUEST['keyword']);
        Tpl::output('show_page', $model_goods->showpage());
        Tpl::showpage('mb_special_widget.goods', 'null_layout');
    }

    /**
     * 更新项目排序
     */
    public function update_item_sortOp() {
        $item_id_string = $_POST['item_id_string'];
        $special_id = $_POST['special_id'];
        if(!empty($item_id_string)) {
            $model_mb_special = Model('mb_special');
            $item_id_array = explode(',', $item_id_string);
            $index = 0;
            foreach ($item_id_array as $item_id) {
                $result = $model_mb_special->editMbSpecialItemByID(array('item_sort' => $index), $item_id, $special_id);
                $index++;
            }
        }
        $data = array();
        $data['message'] = '操作成功';
        echo json_encode($data);
    }

    /**
     * 更新项目启用状态
     */
    public function update_item_usableOp() {
        $model_mb_special = Model('mb_special');
        $result = $model_mb_special->editMbSpecialItemUsableByID($_POST['usable'], $_POST['item_id'], $_POST['special_id']);
        $data = array();
        if($result) {
            $data['message'] = '操作成功';
        } else {
            $data['error'] = '操作失败';
        }
        echo json_encode($data);
    }

    public function add_tabOp()
    {
        $tab_name = $_POST['tab_name'];
        $special_id = intval($_POST['special_id']);
        $sort = intval($_POST['tab_sort']);

        $result = true;
        if ($special_id >= 0 && !empty($tab_name) && $sort > 0)
        {
            $mod_webcode = Model('web_code');
            $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
            foreach ($tabs as $tab)
            {
                if($tab['special_id'] == $special_id) {
                    $result = false;
                    break;
                }
            }
            if($result == true) {
                $tabs[] = array('special_id' => $special_id, 'name' => $tab_name, 'sort' => $sort);
                $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs));
            } else {
                $result = false;
            }
        }
        else {
            $result = false;
        }

        if($result) {
            $this->log('添加首页标签' . '[ID:' . $result. ']', 1);
            showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'tab_list'));
        } else {
            $this->log('添加首页标签' . '[ID:' . $result. ']', 0);
            showMessage(L('nc_common_save_fail'), urlAdmin('mb_special', 'tab_list'));
        }
    }

    public function del_tabOp()
    {
        $special_id = $_POST['special_id'];

        $result = false;
        if ($special_id >= 0)
        {
            $mod_webcode = Model('web_code');
            $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);

            $tabs_new = [];
            foreach ($tabs as $key => $val)
            {
                if($val['special_id'] != $special_id) {
                    $tabs_new[] = $val;
                } else {
                    $result = true;
                }
            }
            if($result == true) {
                $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs_new));
            }
        }

        if($result) {
            $this->log('删除首页标签' . '[ID:' . $_POST['special_id'] . ']', 1);
            showMessage(L('nc_common_del_succ'), urlAdmin('mb_special', 'tab_list'));
        } else {
            $this->log('删除首页标签' . '[ID:' . $_POST['special_id'] . ']', 0);
            showMessage(L('nc_common_del_fail'), urlAdmin('mb_special', 'tab_list'));
        }
    }

    public function update_tab_nameOp()
    {
        $tab_name = $_GET['value'];
        $special_id = intval($_GET['id']);

        $data = array();
        $data['result'] = false;

        if ($special_id >= 0 && !empty($tab_name))
        {
            $mod_webcode = Model('web_code');
            $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
            foreach ($tabs as &$tab)
            {
                if($tab['special_id'] == $special_id) {
                    $tab['name'] = $tab_name;
                    $data['result'] = true;
                    break;
                }
            }
            if($data['result'] == true) {
                $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs));
            }
        }

        if($data['result'] == true) {
            $data['message'] = '操作成功';
        } else {
            $data['error'] = '操作失败';
        }
        echo json_encode($data);die;
    }
    public function update_tab_sortOp()
    {
        $tab_sort = $_GET['value'];
        $special_id = intval($_GET['id']);

        $data = array();
        $data['result'] = false;

        if ($special_id >= 0 && $tab_sort > 0)
        {
            $mod_webcode = Model('web_code');
            $tabs = $mod_webcode->get_nocache(self::mb_home_tab_id);
            foreach ($tabs as &$tab)
            {
                if($tab['special_id'] == $special_id) {
                    $tab['sort'] = $tab_sort;
                    $data['result'] = true;
                    break;
                }
            }
            if($data['result'] == true) {
                $mod_webcode->edit(self::mb_home_tab_id,serialize($tabs));
            }
        }

        if($data['result'] == true) {
            $data['message'] = '操作成功';
        } else {
            $data['error'] = '操作失败';
        }
        echo json_encode($data);die;
    }

    /**
     * 专题审核
     */
    public function ugc_listOp()
    {
        $special_id   = intval($_REQUEST['search_special_id']);
        $special_desc = trim($_REQUEST['special_desc']);
        $state_sel    = intval($_REQUEST['state_sel']);

        if($special_id > 0) {
            $cond = ["special_id" => $special_id];
        }
        elseif(!empty($special_desc)) {
            $cond = ["special_desc" => array('like', "%{$special_desc}%")];
        } else {
            $cond = [];
        }

        $cond['from_user'] = 1;
        if($state_sel == 1) {
            $cond['check_time'] = 0;
            $cond['state'] = 0;
        }
        elseif($state_sel == 2) {
            $cond['check_time'] = ['gt',0];
            $cond['state'] = 1;
        }
        elseif($state_sel == 3) {
            $cond['check_time'] = ['gt',0];
            $cond['state'] = 0;
        }
        else {
        }

        $model_mb_special = Model('mb_special');
        $items = $model_mb_special->getMbSpecialList($cond, 50);

        $uids = [];
        foreach ($items as $item) {
            $sender = intval($item['member_id']);
            $uids[] = $sender;
        }
        $members = $this->users($uids);

        foreach ($items as &$item) {
            $userid = intval($item['member_id']);
            $item['nickname'] = $members[$userid]['nickname'];
        }

        Tpl::output('list', $items);
        Tpl::output('page', $model_mb_special->showpage(2));
        $this->show_menu('ugc_list');
        tpl::output('item_title', '用户内容审核');

        Tpl::showpage('mb_special.review');
    }

    private function users($user_ids)
    {
        if(empty($user_ids)) return [];

        $mod_member = Model('member');
        $members = $mod_member->getMemberList(array('member_id' => ['in',$user_ids]));
        if(empty($members)) return [];

        $result = [];
        foreach ($members as $item)
        {
            $member = new member_info($item);
            $mid = $member->member_id();
            $val['avatar'] = $member->avatar();
            $val['nickname'] = $member->nickname();

            $result[$mid] = $val;
        }
        return $result;
    }

    /**
     * 页面内导航菜单
     * @param string 	$menu_key	当前导航的menu_key
     * @param array 	$array		附加菜单
     * @return
     */
    private function show_menu($menu_key='') {
        $menu_array = array();
        if($menu_key == 'index_edit') {
            $menu_array[] = array('menu_key'=>'index_edit', 'menu_name'=>'编辑', 'menu_url'=>'javascript:;');
        }
        elseif($menu_key == 'special_list' || $menu_key == 'tab_list') {
            $menu_array[] = array('menu_key'=>'special_list','menu_name'=>'列表', 'menu_url'=>urlAdmin('mb_special', 'special_list'));
            $menu_array[] = array('menu_key'=>'tab_list','menu_name'=>'首页标签', 'menu_url'=>urlAdmin('mb_special', 'tab_list'));
        }
        else {
            $menu_array[] = array('menu_key'=>'ugc_list','menu_name'=>'用户内容列表', 'menu_url'=>urlAdmin('mb_special', 'ugc_list'));
        }

        if($menu_key == 'special_item_list') {
            $menu_array[] = array('menu_key'=>'special_item_list', 'menu_name'=>'编辑专题', 'menu_url'=>'javascript:;');
        }
        if($menu_key == 'index_edit') {
            tpl::output('item_title', '首页编辑');
        } else {
            tpl::output('item_title', '专题设置');
        }
        Tpl::output('menu', $menu_array);
        Tpl::output('menu_key', $menu_key);
    }

    public function check_ugcOp()
    {
        $state      = $_GET['state'];
        $special_id = intval($_GET['special_id']);
        if($special_id > 0)
        {
            $mod_special = Model('mb_special');
            $special_info = $mod_special->getMbSpecialByID($special_id,'*');
            $special = new ugc\special($special_info);

            if($state == 'pass') {
                $mod_special->editUserSpecial($special_id,['special_id' => $special_id], ['state' => 0,'check_time' => time()]);
                QueueClient::push('onAsyncUgcPublish',['special_id' => $special_id]);
            }
            elseif($state == 'unpass') {
                $mod_special = Model('mb_special');
                $mod_special->editUserSpecial($special_id,['special_id' => $special_id], ['state' => 1,'check_time' => time()]);
                QueueClient::push('onAsyncUgcDel',['special_id' => $special_id]);
            }
            else {

            }
        }
        showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'ugc_list'));
    }
}