<?php

	namespace app\admin\controller;
	use cmf\controller\AdminBaseController;
	use cmf\lib\Upload;
	use think\Db;
	class ConfigureController extends AdminBaseController {

		//基础配置
		public function index(){
			$shuju = $this->request->param();
			if ($this->request->isPost()) {
				$isok = cmf_set_option('site_info',$shuju,true);
				if ($isok) {
					$data = array('status'=>1,'info'=>'保存成功');
				} else {
					$data = array('status'=>0,'info'=>'保存失败！');
				}
				return json($data);
			} else {
				$mpWechatConfig = cmf_get_option('mp_wechat_config');
				$this->assign('mpWechatConfig',$mpWechatConfig);


				$site_info = cmf_get_site_info();
				$this->assign('dhxz',7);
				$this->assign('title','系统配置');
				$this->assign('site_info',$site_info);
				$this->assign('extranet_website_icon',cmf_get_image_url($site_info['extranet_website_icon']));
				$this->assign('backstage_website_icon',cmf_get_image_url($site_info['backstage_website_icon']));
				$this->assign('website_logo',cmf_get_image_url($site_info['website_logo']));
				$this->assign('scratch_logo',cmf_get_image_url($site_info['scratch_logo']));
				$this->assign('backstage_website_background',cmf_get_image_url($site_info['backstage_website_background']));
				return $this->fetch();
			}
		}

				//基础配置
		public function wechat(){
			$data = $this->request->param();
			if ($this->request->isPost()) {
				$isok = cmf_set_option('mp_wechat_config',$data,true);
				if ($isok) {
					$data = array('status'=>1,'info'=>'保存成功');
				} else {
					$data = array('status'=>0,'info'=>'保存失败！');
				}
				return json($data);
			}
		}

		//上传logo文件
		public function upload(){
			$shuju = $this->request->param();
			if ($this->request->isPost()) {
				$uploader = new Upload();
				$result = $uploader->upload();
				if ($result === false) {
					$data = array('status'=>0,'info'=>$uploader->getError());
					return json($data);
				} else {
					$data = array('status'=>1,'info'=>'上传成功','filepath'=>$result['filepath']);
					return json($data);
				}
			}
		}

	}