1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use app\Request;
- use think\Db;
- use think\Model;
- class HouseFloor extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'title' => input('title','','trim'),
- 'img' => input('img'),
- 'building_id' => input('buildingId/d',0),
- 'org_id' => input('orgId/d',0),
- ];
- $result = validate('HouseFloor')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('HouseFloor')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function del($id){
- $res = Db::name('House')->where('floor_id',$id)->where('del',0)->find();
- if($res){
- HelpHander::error('已被使用无法删除');
- }
- $ret = $this->where('id',$id)->delete();
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function lists($page,$size,$title,$orgId){
- $map[] = ['org_id','=',$orgId];
- if($title != ''){
- $map[] = ['title','like','%'.$title.'%'];
- }
- $lists = $this
- ->where($map)
- ->page($page,$size)
- ->order('id asc')
- ->select();
- $lists = $lists?$lists->toArray():[];
- foreach ($lists as $k=>$v){
- $building = Db::name('house_building')->where('id',$v['building_id'])->find();
- $community = Db::name('house_community')->where('id',$building['community_id'])->find();
- $district = Db::name('house_district')->where('id',$community['district_id'])->find();
- $lists[$k]['buildingName'] = $building['title'];
- $lists[$k]['community_id'] = $building['community_id'];
- $lists[$k]['district_id'] = $community['district_id'];
- $lists[$k]['communityName'] = $community['title'];
- $lists[$k]['districtName'] = $district['title'];
- }
- $total = $this->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists
- ];
- return $data;
- }
- }
|