<?php
namespace app\api\controller\v1;

use app\api\controller\Base;
use app\hander\HelpHander;
use think\Db;

class HouseFloorInfo extends Base
{
    public function floorInfo(){
        $bulidingInfo=Db::table('house_building')
                ->field('id,title,type')
                ->where('org_id',$this->orgId)
                ->select();
            if($bulidingInfo){
                foreach ($bulidingInfo as $k=>$val){
                    if($val['type']==2){
                        $trunInfo=Db::table('house_turn')
                            ->where([
                                'enable'=>1,
                                'del'=>0,'status'=>0,
                                'building_id'=>$val['id'],
                                'org_id'=>$this->orgId
                            ])
                            ->select();
                        $authInfo=Db::table('house_auth')
                            ->field('type,ids')
                            ->where([
                                'type'=>$val['type'],
                                'user_id'=>$this->userId,
                                'org_id'=>$this->orgId
                            ])
                            ->find();
                        $arrayIds=explode(',',$authInfo['ids']);
                        foreach ($trunInfo as $v){
                            if(in_array($v['level_id'],$arrayIds)){
                                $ret=Db::table('house_turn')
                                    ->where([
                                        'enable'=>1,
                                        'del'=>0,
                                        'status'=>0,
                                        'building_id'=>$val['id'],
                                        'org_id'=>$this->orgId
                                    ])
                                    ->select();
                            }else{
                                $ret= [];
                            }
                        }
                    }
                }
            }else{
                $ret=[];
            }

                 HelpHander::success($ret);

        }

}