public function actionDeleteAll() { if (Yii::$app->user->getIdentity()->admin != 1) { Yii::$app->getSession()->setFlash('success', NULL); Yii::$app->getSession()->setFlash('error', "对不起, 你没有权限!"); return $this->redirect(array('index')); } if (!array_key_exists('selection', Yii::$app->request->post())) { Yii::$app->getSession()->setFlash('error', '未选择设备组!'); return $this->redirect(['index']); } $select = Yii::$app->request->post()['selection']; $success_msg = ""; $err_msg = ""; foreach ($select as $k => $v) { $model = $this->findModel($v); ///判断用户是否和该设备池子属于一个系统组 $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $model['gid']]); if ($query == NULL) { $err_msg .= $model['ngroup_name'] . ":没有权限删除" . "<br>"; continue; } ///判断设备池是否为空 $node = DcmdNode::find()->where(['ngroup_id' => $v])->one(); if ($node) { $err_msg .= $model['ngroup_name'] . ':设备池子不为空,不可删除' . "<br>"; continue; } DcmdNodeGroupAttr::deleteAll(['ngroup_id' => $model->ngroup_id]); $model->delete(); $success_msg .= $model['ngroup_name'] . ":删除成功" . "<br>"; } if ($success_msg != "") { Yii::$app->getSession()->setFlash('success', $success_msg); } if ($err_msg != "") { Yii::$app->getSession()->setFlash('error', $err_msg); } return $this->redirect(['index']); }
public function actionDeleteAll() { if (Yii::$app->user->getIdentity()->admin != 1) { Yii::$app->getSession()->setFlash('success', NULL); Yii::$app->getSession()->setFlash('error', "对不起, 你没有权限!"); return $this->redirect(array('index')); } if (!array_key_exists('selection', Yii::$app->request->post())) { Yii::$app->getSession()->setFlash('error', '未选择属性!'); return $this->redirect(['index']); } $select = Yii::$app->request->post()['selection']; foreach ($select as $k => $v) { $model = $this->findModel($v); DcmdNodeGroupAttr::deleteAll(['attr_name' => $model->attr_name]); $model->delete(); } Yii::$app->getSession()->setFlash('success', "删除成功"); return $this->redirect(['index']); }