BuildController.class.php.bak.20200601 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class BuildController extends ComController {
  5. public function _initialize() {
  6. parent::_initialize();
  7. $this->dbname ='building';
  8. }
  9. public function index(){
  10. $Data=I();
  11. if(isset($Data['list'])){
  12. $ModelList=M("building");
  13. $GetPage=$Data['pageCurrent'];//第几页
  14. $GetSize=$Data['pageSize'];//每页条数
  15. $Gage=($GetPage-1)*$GetSize;
  16. $Map=array();
  17. if(!empty($Data['build_name']))
  18. {
  19. $Map['build_name']=array('like','%'.$Data['build_name'].'%');
  20. }
  21. if( session('zt_username')!='admin'&&session('zt_username')!='zj' )
  22. {
  23. $por=$this->getbuild();
  24. $Map['id']=array('in',$por);
  25. if(empty($por))
  26. {
  27. $Map['id']='';
  28. }
  29. //file_put_contents("/var/www/html/log/log.txt",print_r($por,true), FILE_APPEND);
  30. }
  31. $Count= $ModelList->where($Map)->count();// 查询满足要求的总记录数
  32. $ListData = $ModelList->field('id,build_name,addr1,addr2,addr3,address,add_time,add_man')->where($Map)->order('id desc')->limit($Gage,$GetSize)->select();
  33. $InfoList = array(
  34. 'totalRow' => $Count,
  35. //'pageSize' => $count,//分页时不传
  36. 'list' => $ListData,
  37. );
  38. echo json_encode($InfoList);
  39. }
  40. else
  41. {
  42. $this->display();
  43. }
  44. }
  45. public function getbuild(){
  46. $build=M()->query("
  47. SELECT building_id FROM sp_owner_company WHERE owner_id in(SELECT owner_code FROM sp_owner_weibao WHERE agentid='".$_SESSION['zt_username']."')
  48. UNION
  49. SELECT id as building_id FROM sp_building WHERE add_man='".$_SESSION['zt_username']."'");
  50. $arr=array();
  51. foreach ($build as $value) {
  52. $arr[]=$value['building_id'];
  53. }
  54. return $arr;
  55. }
  56. /**
  57. * 检查新增前的action
  58. * @assign role array 返回页面参数(角色信息)
  59. * @assign group array 返回页面参数(部门信息)
  60. * @assign action string 返回页面参数(提交时的动作)
  61. */
  62. public function _befor_add(){
  63. $this->assign('action','/home/Build/add');
  64. }
  65. /**
  66. * 检查新增时需要编辑的字段
  67. * @param data array 页面提交的数据源,包含post|get
  68. * @return array 编辑后的数据源
  69. */
  70. public function _befor_insert($Data){
  71. $Count=M("building")->where(array('build_name'=>$Data['build_name']))->count();
  72. if ($Count==1)
  73. {
  74. $this->mtReturn(300,'建筑物名称已存在!');
  75. }
  76. $Data['add_man']=session('zt_username');
  77. $Data['add_time']=date('Y-m-d H:i:s');
  78. return $Data;
  79. }
  80. public function edit(){
  81. $data=I();
  82. switch ($data['type']) {
  83. case 'owner':
  84. $Owner=M('building');
  85. $list=$Owner->where(array('id'=> $data['id']))->select();//二维数组
  86. $this->assign('Ownerlist',$list[0]);
  87. $this->assign('action','/home/Build/edit');
  88. $this->assign('owner_code_uid',$data['owner_code']);
  89. $this->display();
  90. break;
  91. case 'savaowner':
  92. $owner=M('building');
  93. if(!empty($data['ownerid'])){
  94. $res = $owner->where(array('id'=> $data['ownerid']))->save($data);
  95. if($res)
  96. {
  97. $this->mtReturn(200,'配置成功');
  98. }
  99. else
  100. {
  101. echo json_encode(array('statusCode'=> 300,'message'=>'配置未改变'));
  102. }
  103. }
  104. break;
  105. default:
  106. $this->mtReturn(300,'打开失败联系管理员!');
  107. break;
  108. }
  109. }
  110. public function del(){
  111. $data=I();
  112. if(!empty($data['id'])){
  113. $device=M('owner_device');
  114. $res = $device->delete($data['id']);
  115. if($res){
  116. echo json_encode($this->mtReturn(200,'删除成功'));
  117. }else{
  118. echo json_encode(array('statusCode'=> 300,'message'=>'删除失败'));
  119. }
  120. }
  121. }
  122. }