<?php

/***************************************************************\
|                                                               |
|   开单大师 - 专业的房产ERP管理                                  |
|                                                               |
|   © 2019 http://www.kaidandashi.com All rights reserved.      |
|                                                               |
|   开单大师由淮南市银泰软件科技有限公司提供技术                    |
|                                                               |
|   QQ:984784483                                                |
|                                                               |
\***************************************************************/

namespace Admin\Controller;
use Think\Controller;
class OptionsController extends CommonController {

    public function chengjiao(){
        if (IS_POST) {
            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,
            );
            $chengjiao_json = json_encode($arr);
            $isok=M('options')->where(array('option_name'=>'chengjiao_options'))->setField('option_value',$chengjiao_json);
            if ($isok) {
                $this->success('保存成功!');
            } else {
                $this->error('保存失败!');
            }
        }else{
            $chengjiao_options=M('options')->where(array('option_name'=>'chengjiao_options'))->find();
            $options_arr = json_decode($chengjiao_options['option_value'],true);
            $this->arr = $options_arr;
            $fyfpzt=$options_arr['fyfengpan_zhuangtai'];
            $kyfpzt=$options_arr['kyfengpan_zhuangtai'];
            $this->fyfpzt=M('peizhi')->where("pzming = 'zhuangtai' and zhuangtai = 1 and lxid <> ".$options_arr['fygongpan_zhuangtai']." and lxid <> ".$options_arr['fysipan_zhuangtai'])->order('xsshunxu asc')->select();
            $this->kyfpzt=M('peizhi')->where("pzming = 'khzhuangtai' and zhuangtai = 1 and lxid <> ".$options_arr['kygongke_zhuangtai']." and lxid <> ".$options_arr['kysike_zhuangtai'])->order('xsshunxu asc')->select();
            $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->display();
        }
    }

    public function diaoqu(){
        if (IS_POST) {
            $data = I('data');
            $diaoqu_json = json_encode($data);
            $isok=M('options')->where(array('option_name'=>'diaoqu_options'))->setField('option_value',$diaoqu_json);
            if ($isok) {
                $this->success('保存成功!');
            } else {
                $this->error('保存失败!');
            }
        }else{
            $guohu_options=M('options')->where(array('option_name'=>'diaoqu_options'))->find();
            $this->arr = json_decode($guohu_options['option_value'],true);
            $this->role = M('role')->select();
            $this->display();
        }
    }
}