<?php

	/***************************************************************\
	|																|
	|	房哨（专业的房产运营ERP管理系统）								|
	|																|
	|	© 2019 http://fs.ytsofts.cn/ All rights reserved.			|
	|																|
	|	本系统由淮南市银泰软件科技有限公司提供技术支持					|
	|																|
	|	QQ号：984784483												|
	|																|
	\***************************************************************/

	namespace Erpadmin\Controller;
	use Think\Controller;
	class OptionsController extends ErpadminbaseController {

		//配置设置列表
		public function Pzshezhi(){
			$condition = "zhuangtai = 1";
			$pzfl=I('pzfl');
			$sousuo=I('sousuo');
			if ($pzfl) {
				$condition.=" and pzfl=$pzfl";
			}
			if ($sousuo) {
				$condition.=" and ((pzming like '%$sousuo%') or (zhushi like '%$sousuo%'))";
			}
			$Model = new \Think\Model;
			$count=$Model->query("select count(*) from (select count(*) from jjrxt_peizhi where {$condition} group by pzming) a");
			$Page=new \Think\Page($count['0']['count(*)'],15);
			$show=$Page->show();
			$list="select max(id),pzming,zhushi from jjrxt_peizhi where {$condition} group by pzming order by id DESC limit ".$Page->firstRow.','.$Page->listRows;
			$Peizhi=$Model->query($list);
			$this->assign('peizhi',$Peizhi);
			$this->assign('count',$count);
			$this->assign('page',$show);
			$this->pzfl=get_peizhi('pzfl',0,1);
			$this->display();
		}

		//添加配置类型
		public function addPzshezhi(){
			if (IS_POST) {
				$dqpz=M('peizhi')->where(array('gongsiid'=>session("gongsiid"),'pzming' =>I('pzming')))->order('lxid desc')->field('lxid,pzfl')->find();
				$data['gongsiid'] = session('gongsiid');
				$data['pzming']=I('pzming');
				$data['zhushi']=I('zhushi');
				$data['lxid']=$dqpz['lxid']+1;
				$data['lxming']=I('lxming');
				$data['xsshunxu']=I('xsshunxu');
				$data['pzfl']=$dqpz['pzfl'];
				if (M('peizhi')->add($data)) {
					$this->success('添加成功');
				}else{
					$this->error('添加失败');
				}
			} else {
				$this->peizhi=M('peizhi')->where(array('gongsiid'=>session("gongsiid"),'id'=>I('id')))->find();
				$this->display();
			}
		}

		//更新配置类型
		public function editPzshezhi(){
			if (IS_POST) {
				$Peizhi=M("peizhi");
				$data['lxming']=I('lxming');
				$data['xsshunxu']=I('xsshunxu');
				$Peizhi->where(array('gongsiid'=>session("gongsiid"),'id'=>I('id')))->save($data);
				if ($Peizhi){
					$this->success('更新成功');
				}else{
					$this->error('更新失败');
				}
			} else {
				$this->peizhi=M('peizhi')->where(array('gongsiid'=>session("gongsiid"),'id'=>I('id')))->find();
				$this->display();
			}
		}

		//删除配置类型
		public function delPzshezhi(){
			$data['zhuangtai']=0;
			if (M('peizhi')->where(array('gongsiid'=>session("gongsiid"),'id'=>I('id')))->save($data)) {
				$this->success('修改成功');
			}else{
				$this->error('修改失败');
			}
		}

		//关联
		public function guanlian(){
			$qxpdep = get_node_range(MODULE_NAME,'Peizhi','editPzshezhi') == true? '1': '0';
			$qxpddp = get_node_range(MODULE_NAME,'Peizhi','delPzshezhi') == true? '1': '0';
			$id=I('id');
			$where['id']=$id;
			$pzming=get_pzmzs($id,1);
			$leixing=get_peizhi($pzming,0,1);
			$data=array('status'=>0,'leixing'=>$leixing,'qxpdep'=>$qxpdep,'qxpddp'=>$qxpddp);
			header("Content-type: application/json");
			exit(json_encode($data));
		}

	}