<?php

namespace app\admin\controller;

use think\Lang;

class Contact 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_contact = model('Contact');
        $allpower = $this->qxhans();
        $this->assign('allpower',$allpower);
        if (!request()->isPost()) {
            $contact = $model_contact->getContact();
            $contact['update_time'] = date("Y-m-d h:i:s",$contact['update_time']);
            $this->assign('contact', $contact);
            $this->setAdminCurItem('index');
            return $this->fetch();
        } else {
            $update_array = array();
            $update_array['address'] = input('post.address');
            $update_array['phone'] = input('post.phone');
            $update_array['email'] = input('post.email');
            $update_array['fax'] = input('post.fax');
            $update_array['detail'] = input('post.detail');
            $update_array['update_time'] = time();

            $result = $model_contact->updateContact($update_array);
            if ($result === 1) {
                $this->log(lang('ds_edit') . lang('dis_dump'), 1);
                $this->success('修改成功', 'Contact/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;
    }

}
