Model 在Yii2中显示与给定给用户的节点相关的记录

Model 在Yii2中显示与给定给用户的节点相关的记录,model,yii2,yii2-advanced-app,Model,Yii2,Yii2 Advanced App,我正在做yii2。我有一个视图,其中我正在向用户显示一些数据。存在具有节点的用户层次结构 用户已附加到节点 节点已附加到客户 将节点分配给客户时,将在所选节点下创建客户。子节点not(即customer)也具有父节点id,该id告诉此客户已附加到该节点 客户被连接到一个仪表上 下面是我正在显示的数据 我想做什么? 在我上面的视图中,我只想显示与给定给用户的节点一起附加的客户ID和仪表数据 在我的搜索模型中 public function search($params) { if(

我正在做
yii2
。我有一个视图,其中我正在向用户显示一些数据。存在具有节点的用户层次结构

  • 用户已附加到节点
  • 节点已附加到客户
  • 将节点分配给客户时,将在所选节点下创建客户。子节点not(即customer)也具有父节点id,该id告诉此客户已附加到该节点

  • 客户被连接到一个仪表上
  • 下面是我正在显示的数据

    我想做什么?

    在我上面的视图中,我只想显示与给定给用户的节点一起附加的
    客户ID
    仪表
    数据

    在我的
    搜索模型中

    public function search($params)
    {
        if(Yii::$app->user->identity->user_role ==1)
        {
          // do nothing as the user is admin
        }
        else
        {
            $user_id = \Yii::$app->user->id;           
    
        }
    
    
        $query = MdcmetersData::find();
    
        // add conditions that should always apply here
    
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
    
        $this->load($params);
    
        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }
    
        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'cust_id'=>$this->cust_id,
            'data_date_time' => $this->data_date_time,
        ]);
    
        $query->andFilterWhere(['like', 'msn', $this->msn])
            ->andFilterWhere(['like', 'device_id', $this->device_id])
            ->andFilterWhere(['like','cust_id', $this->cust_id])
            ->andFilterWhere(['like', 'kwh_t', $this->kwh_t])
            ->andFilterWhere(['like','d_type', $this->d_type])
            ->andFilterWhere(['like', 'voltage_p1', $this->voltage_p1])
            ->andFilterWhere(['like', 'voltage_p2', $this->voltage_p2])
            ->andFilterWhere(['like', 'voltage_p3', $this->voltage_p3])
            ->andFilterWhere(['like', 'current_p1', $this->current_p1])
            ->andFilterWhere(['like', 'current_p2', $this->current_p2])
            ->andFilterWhere(['like', 'current_p3', $this->current_p3])
            ->andFilterWhere(['like', 'data_date_time', $this->data_date_time]);
    
        $query->andWhere(['not',['cust_id'=>null]]);
        $query->andWhere(['not',['cust_id'=>'']]);
        $query->orderBy(['data_date_time' => SORT_DESC]);
        return $dataProvider;
    }
    
    节点表(mdc\U节点)

    I上表
    GIS办公室
    客户
    ,附在
    一楼
    下。将客户与节点连接时,将在所选节点(即子节点)下创建一个新节点

    注意:父节点下可以有多个子节点