123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace Home\Controller;
- use Think\Controller;
- class BuildController extends ComController {
- public function _initialize() {
- parent::_initialize();
- $this->dbname ='building';
- }
- public function index(){
- $Data=I();
- if(isset($Data['list'])){
- $ModelList=M("building");
- $GetPage=$Data['pageCurrent'];//第几页
- $GetSize=$Data['pageSize'];//每页条数
- $Gage=($GetPage-1)*$GetSize;
- $Map=array();
- if(!empty($Data['build_name']))
- {
- $Map['build_name']=array('like','%'.$Data['build_name'].'%');
- }
-
- if( session('zt_username')!='admin'&&session('zt_username')!='zj' )
- {
- $por=$this->getbuild();
- $Map['id']=array('in',$por);
- if(empty($por))
- {
- $Map['id']='';
- }
- //file_put_contents("/var/www/html/log/log.txt",print_r($por,true), FILE_APPEND);
- }
- $Count= $ModelList->where($Map)->count();// 查询满足要求的总记录数
- $ListData = $ModelList->field('id,build_name,addr1,addr2,addr3,address,add_time,add_man')->where($Map)->order('id desc')->limit($Gage,$GetSize)->select();
- $InfoList = array(
- 'totalRow' => $Count,
- //'pageSize' => $count,//分页时不传
- 'list' => $ListData,
- );
- echo json_encode($InfoList);
- }
- else
- {
- $this->display();
- }
- }
- public function getbuild(){
- $build=M()->query("
- SELECT building_id FROM sp_owner_company WHERE owner_id in(SELECT owner_code FROM sp_owner_weibao WHERE agentid='".$_SESSION['zt_username']."')
- UNION
- SELECT id as building_id FROM sp_building WHERE add_man='".$_SESSION['zt_username']."'");
- $arr=array();
- foreach ($build as $value) {
- $arr[]=$value['building_id'];
- }
- return $arr;
- }
- /**
- * 检查新增前的action
- * @assign role array 返回页面参数(角色信息)
- * @assign group array 返回页面参数(部门信息)
- * @assign action string 返回页面参数(提交时的动作)
- */
- public function _befor_add(){
- $this->assign('action','/home/Build/add');
- }
- /**
- * 检查新增时需要编辑的字段
- * @param data array 页面提交的数据源,包含post|get
- * @return array 编辑后的数据源
- */
- public function _befor_insert($Data){
- $Count=M("building")->where(array('build_name'=>$Data['build_name']))->count();
- if ($Count==1)
- {
- $this->mtReturn(300,'建筑物名称已存在!');
- }
- $Data['add_man']=session('zt_username');
- $Data['add_time']=date('Y-m-d H:i:s');
- return $Data;
- }
- public function edit(){
- if (session('power')==2){
- $this->mtReturn(300,'本账号没有该权限,如需开通请联系管理员',1);
- }else {
- $data = I();
- switch ($data['type']) {
- case 'owner':
- $Owner = M('building');
- $list = $Owner->where(array('id' => $data['id']))->select();//二维数组
- $this->assign('Ownerlist', $list[0]);
- $this->assign('action', '/home/Build/edit');
- $this->assign('owner_code_uid', $data['owner_code']);
- $this->display();
- break;
- case 'savaowner':
- $owner = M('building');
- if (!empty($data['ownerid'])) {
- $res = $owner->where(array('id' => $data['ownerid']))->save($data);
- if ($res) {
- $this->mtReturn(200, '配置成功');
- } else {
- echo json_encode(array('statusCode' => 300, 'message' => '配置未改变'));
- }
- }
- break;
- default:
- $this->mtReturn(300, '打开失败联系管理员!');
- break;
- }
- }
- }
- public function del(){
- $data=I();
- if(!empty($data['id'])){
- $device=M('owner_device');
- $res = $device->delete($data['id']);
- if($res){
- echo json_encode($this->mtReturn(200,'删除成功'));
- }else{
- echo json_encode(array('statusCode'=> 300,'message'=>'删除失败'));
- }
- }
- }
- }
|