/** * 告警级别黑名单 */ public function actionLevelBlacklist() { if (Yii::$app->request->isPost) { $level = Yii::$app->request->post('level'); $m = AlarmLevel::findOne(["id" => $level]); $exist = AlarmLevelBlacklist::find()->where(["level" => $level])->count(); if ($m && !$exist) { $model = new AlarmLevelBlacklist(['level' => $level, "level_name" => $m->desc]); $model->save(); echo '<script>alert("操作成功")</script>'; } else { echo '<script>alert("操作失败")</script>'; } } $model = AlarmLevelBlacklist::find(); $provider = new ActiveDataProvider(['query' => $model]); $ids = AlarmLevelBlacklist::find()->select("level")->column(); $ids[] = 255; $lists = AlarmLevel::find()->where(['not', ['id' => $ids]])->asArray()->all(); $lists = ArrayHelper::map($lists, 'id', 'desc'); return $this->render('blacklist', ['dataProvider' => $provider, 'lists' => $lists]); }