HouseFloor.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use app\Request;
  5. use think\Db;
  6. use think\Model;
  7. class HouseFloor extends Model
  8. {
  9. public function add(){
  10. $data = [
  11. 'id' => input('id/d',0),
  12. 'title' => input('title','','trim'),
  13. 'img' => input('img'),
  14. 'building_id' => input('buildingId/d',0),
  15. 'org_id' => input('orgId/d',0),
  16. ];
  17. $result = validate('HouseFloor')->check($data,[],'');
  18. if(true !== $result){
  19. HelpHander::error(validate('HouseFloor')->getError());
  20. }
  21. $id = $data['id'];
  22. unset($data['id']);
  23. if($id > 0){
  24. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  25. }else{
  26. $ret = $this->allowField(true)->save($data);
  27. }
  28. if(!$ret){
  29. HelpHander::error('操作失败');
  30. }
  31. return true;
  32. }
  33. public function del($id){
  34. $res = Db::name('House')->where('floor_id',$id)->where('del',0)->find();
  35. if($res){
  36. HelpHander::error('已被使用无法删除');
  37. }
  38. $ret = $this->where('id',$id)->delete();
  39. if(!$ret){
  40. HelpHander::error('删除失败');
  41. }
  42. return true;
  43. }
  44. public function lists($page,$size,$title,$orgId){
  45. $map[] = ['org_id','=',$orgId];
  46. if($title != ''){
  47. $map[] = ['title','like','%'.$title.'%'];
  48. }
  49. $lists = $this
  50. ->where($map)
  51. ->page($page,$size)
  52. ->order('id asc')
  53. ->select();
  54. $lists = $lists?$lists->toArray():[];
  55. foreach ($lists as $k=>$v){
  56. $building = Db::name('house_building')->where('id',$v['building_id'])->find();
  57. $community = Db::name('house_community')->where('id',$building['community_id'])->find();
  58. $district = Db::name('house_district')->where('id',$community['district_id'])->find();
  59. $lists[$k]['buildingName'] = $building['title'];
  60. $lists[$k]['community_id'] = $building['community_id'];
  61. $lists[$k]['district_id'] = $community['district_id'];
  62. $lists[$k]['communityName'] = $community['title'];
  63. $lists[$k]['districtName'] = $district['title'];
  64. }
  65. $total = $this->where($map)->count();
  66. $data = [
  67. 'total' => $total,
  68. 'list' => $lists
  69. ];
  70. return $data;
  71. }
  72. }