<?php

	/***************************************************************\
	|																|
	|	开单大师（专业的房产ERP管理系统）								|
	|																|
	|	© 2019 http://www.kaidandashi.com All rights reserved.		|
	|																|
	|	本系统由淮南市银泰软件科技有限公司提供技术支持					|
	|																|
	|	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) {
				if(!preg_match("/^[1-9]\d*$/",I('csgjsj')) || !preg_match("/^[1-9]\d*$/",I('csxzsj')) || !preg_match("/^[1-9]\d*$/",I('cslrsj')) || !preg_match("/^[1-9]\d*$/",I('czgjsj')) || !preg_match("/^[1-9]\d*$/",I('czxzsj')) || !preg_match("/^[1-9]\d*$/",I('czlrsj')) || !preg_match("/^[1-9]\d*$/",I('qggjsj')) || !preg_match("/^[1-9]\d*$/",I('qgxzsj')) || !preg_match("/^[1-9]\d*$/",I('qglrsj')) || !preg_match("/^[1-9]\d*$/",I('qzgjsj')) || !preg_match("/^[1-9]\d*$/",I('qzxzsj')) || !preg_match("/^[1-9]\d*$/",I('qzlrsj'))){
					$this->error('时间请输入非零正整数');
				}
				$sjc=24*3600;
				if(I('csgj')){
					$csgj=1;
				}else{
					$csgj=0;
				}
				if(I('csxz')){
					$csxz=1;
				}else{
					$csxz=0;
				}
				if(I('cslr')){
					$cslr=1;
				}else{
					$cslr=0;
				}
				if(I('czgj')){
					$czgj=1;
				}else{
					$czgj=0;
				}
				if(I('czxz')){
					$czxz=1;
				}else{
					$czxz=0;
				}
				if(I('czlr')){
					$czlr=1;
				}else{
					$czlr=0;
				}
				if(I('qggj')){
					$qggj=1;
				}else{
					$qggj=0;
				}
				if(I('qgxz')){
					$qgxz=1;
				}else{
					$qgxz=0;
				}
				if(I('qglr')){
					$qglr=1;
				}else{
					$qglr=0;
				}
				if(I('qzgj')){
					$qzgj=1;
				}else{
					$qzgj=0;
				}
				if(I('qzxz')){
					$qzxz=1;
				}else{
					$qzxz=0;
				}
				if(I('qzlr')){
					$qzlr=1;
				}else{
					$qzlr=0;
				}
				$data['csgj']=$csgj;
				$data['csxz']=$csxz;
				$data['cslr']=$cslr;
				$data['czgj']=$czgj;
				$data['czxz']=$czxz;
				$data['czlr']=$czlr;
				$data['qggj']=$qggj;
				$data['qgxz']=$qgxz;
				$data['qglr']=$qglr;
				$data['qzgj']=$qzgj;
				$data['qzxz']=$qzxz;
				$data['qzlr']=$qzlr;
				$data['csgjsj']=I('csgjsj')*$sjc;
				$data['csxzsj']=I('csxzsj')*$sjc;
				$data['cslrsj']=I('cslrsj')*$sjc;
				$data['czgjsj']=I('czgjsj')*$sjc;
				$data['czxzsj']=I('czxzsj')*$sjc;
				$data['czlrsj']=I('czlrsj')*$sjc;
				$data['qggjsj']=I('qggjsj')*$sjc;
				$data['qgxzsj']=I('qgxzsj')*$sjc;
				$data['qglrsj']=I('qglrsj')*$sjc;
				$data['qzgjsj']=I('qzgjsj')*$sjc;
				$data['qzxzsj']=I('qzxzsj')*$sjc;
				$data['qzlrsj']=I('qzlrsj')*$sjc;
				$isok=M("fkypz")->where(array('id'=>1))->save($data);
				if ($isok){
					$this->success('更新成功');
				}else{
					$this->error('更新失败');
				}
			}else{
				$this->fkypz=M("fkypz")->where(array('id'=>1))->find();
				$this->sjc=24*3600;
				$this->display();
			}
		}
	}