<?php

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

	namespace Admin\Controller;
	use Think\Controller;
	class PeizhiController extends CommonController {
		//配置设置列表
		public function Pzshezhi(){
			$is_rbac = _rbac_btn_show(421,0);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			$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%'))";
			}
			$count=M('peizhi')->query("select count(*) from (select count(*) from __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 __PEIZHI__ where {$condition} group by pzming order by id DESC limit ".$Page->firstRow.','.$Page->listRows;
			$Peizhi=M('peizhi')->query($list);
			$this->assign('peizhi',$Peizhi);
			$this->assign('count',$count);
			$this->assign('page',$show);
			$this->pzfl=M('Peizhi')->where(array('pzming'=>'pzfl','zhuangtai'=>1))->order('xsshunxu asc')->select();
			$this->display();
		}
		//添加配置类型
		public function addPzshezhi(){
			$is_rbac = _rbac_btn_show(423,0);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if (IS_POST) {
				$dqpz=M('peizhi')->where(array('pzming' =>I('pzming')))->order('lxid desc')->field('lxid,pzfl')->find();
				$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('id'=>I('id')))->find();
				$this->display();
			}
		}
		//更新配置类型
		public function editPzshezhi(){
			$is_rbac = _rbac_btn_show(425,0);
			if (!$is_rbac) {
				$this->redirect('Index/error');
			}
			if (IS_POST) {
				$Peizhi=M("peizhi");
				$data['lxming']=I('lxming');
				$data['xsshunxu']=I('xsshunxu');
				$Peizhi->where(array('id'=>I('id')))->save($data);
				if ($Peizhi){
					$this->success('更新成功');
				}else{
					$this->error('更新失败');
				}
			} else {
				$this->peizhi=M('peizhi')->where(array('id'=>I('id')))->find();
				$this->display();
			}
		}
		//删除配置类型
		public function delPzshezhi(){
			$is_rbac = _rbac_btn_show(427,0);
			if (!$is_rbac) {
				$this->error('异常错误！');
			}
			$data['zhuangtai']=0;
			if (M('peizhi')->where(array('id'=>I('id')))->save($data)) {
				$this->success('修改成功');
			}else{
				$this->error('修改失败');
			}
		}
	}