<?php

	/***************************************************************\
	|																|
	|	开单大师（专业的房产ERP管理系统）							|
	|																|
	|	© 2017-2022 淮南市银泰软件科技有限公司 All rights reserved	|
	|																|
	|	http://www.kaidandashi.com									|
	|																|
	|	QQ号：984784483												|
	|																|
	\***************************************************************/

	namespace Admin\Controller;
	use Think\Controller;
	class ConfigureController extends CommonController {
		Public function index(){
			$this->list1 = M("Configure")->where(array('status'=>1,'group'=>1))->field('id,name,title,extra,value,remark,type')->order('sort')->select();
			$this->list2 = M("Configure")->where(array('status'=>1,'group'=>2))->field('id,name,title,extra,value,remark,type')->order('sort')->select();
			$this->yonghu = M('yonghu')->where(array('dianhua'=>C('RBAC_SUPERADMIN')))->field('id,keyid')->find();
			$this->display();
		}
		/**
			* 批量保存配置
			* @author 
		*/
		public function save($config){
			//写入keyid
			M('yonghu')->where(array('dianhua'=>C('RBAC_SUPERADMIN')))->setField(array('keyid'=>trim(I('keyid'))));
			//读取keyid
			$ckid = M('yonghu')->where(array('dianhua'=>C('RBAC_SUPERADMIN')))->field('keyid')->find(); 
			if($config && is_array($config)){
				unset($config['IS_ZNLYL_XS']);
				unset($config['IS_ZNLYL_SL']);
				unset($config['IS_WXQYH_DL']);
				unset($config['IS_WXQYH_APPID']);
				unset($config['IS_WXQYH_AGENTID']);
				unset($config['IS_WXQYH_APPSECRET']);
				$Config = M('Configure');
				foreach ($config as $name => $value) {
					$map = array('name' => $name);
					if ($name=='IS_LOGIN_KEY') {
						$Config->where($map)->setField('value',empty($ckid['keyid'])? 0 : $value);
						$isloginkey = $value;
						$m = M('Mac')->where(array('macid'=>I('MacID')))->find();
						if (!$m) {
							$data['macid'] = I('MacID');
							$data['keyid'] = I('keyid');
							$data['beizhu'] = '超级管理员';
							$data['tjsj'] = time();
							$data['shenhe'] = 1;
							M('Mac')->add($data);
						}
					}else{
						$Config->where($map)->setField('value', $value);
					}
				}
			}
			S('DB_CONFIG_DATA',null);
			if (empty($ckid['keyid']) && $isloginkey=='1') {
				$this->error('保存失败，开启加密锁登录前，必须给超级管理员绑定加密锁ID！');
			}else{
				$this->success('保存成功！');
			}
		}
		Public function fkypz(){
			if (IS_POST) {
				$this->error('请联系客服（19965783436）获取正式版功能！');
			}else{
				$this->fkypz=M("fkypz")->where(array('id'=>1))->find();
				$this->sjc=24*3600;
				$this->display();
			}
		}
	}