<?php
namespace Erpadmin\Controller;
use Think\Controller;
class ConfigController extends ErpadminbaseController {



	public function index()
	{
		if (IS_POST) {
            k_set_option('site_info',I('option'),1);
            $this->success('更新成功');
        } else {
            $this->site_info = k_get_option('site_info',1);

            $this->site_info = k_get_option('site_info',1);

            $this->fkyzt_config = k_get_option('fkyzt_config',1);

            $fkyzt = $this->fkyzt_config;

            $fkyzt['fygongpan_zhuangtai'] = $fkyzt['fygongpan_zhuangtai']?$fkyzt['fygongpan_zhuangtai']:0;
            $fkyzt['fysipan_zhuangtai'] = $fkyzt['fysipan_zhuangtai']?$fkyzt['fysipan_zhuangtai']:0;
            $fkyzt['kygongke_zhuangtai'] = $fkyzt['kygongke_zhuangtai']?$fkyzt['kygongke_zhuangtai']:0;
            $fkyzt['kysike_zhuangtai'] = $fkyzt['kysike_zhuangtai']?$fkyzt['kysike_zhuangtai']:0;

            $fyfpzt=$fkyzt['fyfengpan_zhuangtai'];
            $kyfpzt=$fkyzt['kyfengpan_zhuangtai'];
            $fyfpztids=explode(",",$fyfpzt);
            foreach ($fyfpztids as $key => $value) {
                $fyfpztid[$value]=$value;
            }
            $kyfpztids=explode(",",$kyfpzt);
            foreach ($kyfpztids as $key => $value) {
                $kyfpztid[$value]=$value;
            }
            $this->fyfpztid=$fyfpztid;
            $this->kyfpztid=$kyfpztid;

            $this->fyfpzt=M('peizhi')->where(" pzming = 'zhuangtai' and zhuangtai = 1 and lxid <> ".$fkyzt['fygongpan_zhuangtai']." and lxid <> ".$fkyzt['fysipan_zhuangtai'])->order('xsshunxu asc')->select();
            $this->kyfpzt=M('peizhi')->where(" pzming = 'khzhuangtai' and zhuangtai = 1 and lxid <> ".$fkyzt['kygongke_zhuangtai']." and lxid <> ".$fkyzt['kysike_zhuangtai'])->order('xsshunxu asc')->select();


            $this->display();
        }
        
	}


    public function fkyzt_config()
    {
        if ((I('fychengjiao_zhuangtai') == I('fygongpan_zhuangtai')) || (I('fychengjiao_zhuangtai') == I('fysipan_zhuangtai')) || ((I('fygongpan_zhuangtai') == I('fysipan_zhuangtai')) && (I('fygongpan_zhuangtai') > 0) && (I('fysipan_zhuangtai') > 0))){
                $this->error('房源状态相同');
        }
        if ((I('kychengjiao_zhuangtai') == I('kygongke_zhuangtai')) || (I('kychengjiao_zhuangtai') == I('kysike_zhuangtai')) || ((I('kygongke_zhuangtai') == I('kysike_zhuangtai')) && (I('kygongke_zhuangtai') > 0) && (I('kysike_zhuangtai') > 0))){
            $this->error('客源状态相同');
        }
        $fyfpzt=I('fyfpzt');
        if ($fyfpzt) {
            foreach ($fyfpzt as $key => $value) {
                if (I('fygongpan_zhuangtai') == $value){
                    $this->error('房源无效状态中有房源公盘状态');
                }
                if (I('fysipan_zhuangtai') == $value){
                    $this->error('房源无效状态中有房源私盘状态');
                }
                $fyarr[]=$value;
            }
        }
        $fyids=implode(",",$fyarr);
        if (!in_array(I('fychengjiao_zhuangtai'), $fyarr)){
            $this->error('房源无效状态中没有房源成交状态');
        }
        $kyfpzt=I('kyfpzt');
        if ($kyfpzt) {
            foreach ($kyfpzt as $key => $value) {
                if (I('kygongke_zhuangtai') == $value){
                    $this->error('客源无效状态中有客源公客状态');
                }
                if (I('kysike_zhuangtai') == $value){
                    $this->error('客源无效状态中有客源私客状态');
                }
                $kyarr[]=$value;
            }
        }
        $kyids=implode(",",$kyarr);
        if (!in_array(I('kychengjiao_zhuangtai'), $kyarr)){
            $this->error('客源无效状态中没有客源成交状态');
        }
        $arr =  array(
            'fychengjiao_zhuangtai'=>I('fychengjiao_zhuangtai'),
            'kychengjiao_zhuangtai'=>I('kychengjiao_zhuangtai'),
            'fygongpan_zhuangtai'=>I('fygongpan_zhuangtai'),
            'kygongke_zhuangtai'=>I('kygongke_zhuangtai'),
            'fysipan_zhuangtai'=>I('fysipan_zhuangtai'),
            'kysike_zhuangtai'=>I('kysike_zhuangtai'),
            'fyfengpan_zhuangtai'=>$fyids,
            'kyfengpan_zhuangtai'=>$kyids,
        );
        k_set_option('fkyzt_config',$arr,1);
        $this->success('更新成功');
    }
}