<?php

namespace app\admin\controller;

use think\Lang;

class Config extends AdminControl {

    public function _initialize() {
        parent::_initialize();
        Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/config.lang.php');
    }

    /**
     * 网站配置
     * @return mixed
     */
    public function index() {
        $model_config = model('config');
        $allpower = $this->qxhans();
        $this->assign('allpower',$allpower);
        if (!request()->isPost()) {
            $list_config = $model_config->getListConfig();
            $this->assign('list_config', $list_config);
            $this->setAdminCurItem('index');
            return $this->fetch();
        } else {
            $update_array = array();
            $update_array['cache_open'] = isset($_POST['cache_open']) ? '1' : '';
            $update_array['guest_comment'] = isset($_POST['guest_comment']) ? '1' : '';
            $update_array['words_open'] = isset($_POST['words_open']) ? '1' : '';
            $update_array['img_open'] = isset($_POST['img_open']) ? '1' : '';
            $update_array['voice_open'] = isset($_POST['voice_open']) ? '1' : '';
            $update_array['video_open'] = isset($_POST['video_open']) ? '1' : '';
            $update_array['look_open'] = isset($_POST['look_open']) ? '1' : '';
            
            $result = $model_config->updateConfig($update_array);
            if ($result === true) {
                $this->log(lang('ds_edit') . lang('dis_dump'), 1);
                $this->success('修改成功', 'Config/index');
            } else {
                $this->log(lang('ds_edit') . lang('dis_dump'), 0);
                $this->error(lang('修改失败'));
            }
        }
    }

    /**
     * 获取卖家栏目列表,针对控制器下的栏目
     */
    protected function getAdminItemList() {
        $menu_array = array(
            array(
                'name' => 'base',
                'text' => lang('site_set'),
                'url' => url('Admin/Config/index')
            ),
        );
        return $menu_array;
    }

}
