显示与Yii2中提供给用户的节点有关的记录

问题描述

我正在研究yii2。我在一个视图中向用户显示一些数据。有节点的用户层次结构。

  1. 用户已附加到节点

enter image description here

  1. 节点已附加到客户

enter image description here

在将节点分配给客户时,将在所选节点下创建客户。没有子项(即客户)的子节点parent_id告诉该客户已附加该节点。

  1. 客户已连接到仪表

enter image description here

我正在显示的数据如下

enter image description here

我想做什么?

在我上面的视图中,我只想显示与给用户节点附加的customer ID'smeters数据。

在我的search model

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_node)

enter image description here

GIS Office上方的I是customer,它附加在Floor-1下。在将客户附加到节点上时,将在所选节点(即子节点)下创建一个新节点。

enter image description here

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)