/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     ///非admin用户,可查看所属业务组内的任务
     $svr_con = "";
     if (Yii::$app->user->getIdentity()->admin != 1) {
         $app_con = "svr_gid in (0";
         $query = DcmdUserGroup::find()->andWhere(['uid' => Yii::$app->user->getId()])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $app_con .= "," . $item['gid'];
             }
         }
         $app_con .= ")";
         $query = DcmdApp::find()->where($app_con)->asArray()->all();
         $app_con = "app_id in (0";
         foreach ($query as $item) {
             $app_con .= "," . $item['app_id'];
         }
         $app_con .= ")";
         $query = DcmdService::find()->where($app_con)->asArray()->all();
         $svr_con = "svr_id in (0";
         foreach ($query as $item) {
             $svr_con .= "," . $item['svr_id'];
         }
         $svr_con .= ")";
     }
     $query = DcmdTaskHistory::find()->where($svr_con)->orderBy('task_id desc');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 20]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['task_id' => $this->task_id, 'depend_task_id' => $this->depend_task_id, 'svr_id' => $this->svr_id, 'update_env' => $this->update_env, 'update_tag' => $this->update_tag, 'state' => $this->state, 'freeze' => $this->freeze, 'valid' => $this->valid, 'pause' => $this->pause, 'concurrent_rate' => $this->concurrent_rate, 'timeout' => $this->timeout, 'auto' => $this->auto, 'process' => $this->process, 'utime' => $this->utime, 'ctime' => $this->ctime, 'opr_uid' => $this->opr_uid]);
     $query->andFilterWhere(['like', 'task_name', $this->task_name])->andFilterWhere(['like', 'task_cmd', $this->task_cmd])->andFilterWhere(['like', 'depend_task_name', $this->depend_task_name])->andFilterWhere(['like', 'svr_name', $this->svr_name])->andFilterWhere(['like', 'svr_path', $this->svr_path])->andFilterWhere(['like', 'tag', $this->tag])->andFilterWhere(['like', 'err_msg', $this->err_msg])->andFilterWhere(['like', 'task_arg', $this->task_arg])->andFilterWhere(['like', 'comment', $this->comment]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     ///应用组用户只可查看所在组的应用
     $svr_con = "";
     if (Yii::$app->user->getIdentity()->admin != 1) {
         $app_con = "svr_gid in (0";
         $query = DcmdUserGroup::find()->andWhere(['uid' => Yii::$app->user->getId()])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $app_con .= "," . $item['gid'];
             }
         }
         $app_con .= ")";
         $query = DcmdApp::find()->where($app_con)->asArray()->all();
         $svr_con = "app_id in (0";
         foreach ($query as $item) {
             $svr_con .= "," . $item['app_id'];
         }
         $svr_con .= ")";
     }
     $query = DcmdService::find()->where($svr_con)->orderBy('svr_name');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 20]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['svr_id' => $this->svr_id, 'app_id' => $this->app_id, 'owner' => $this->owner, 'utime' => $this->utime, 'ctime' => $this->ctime, 'opr_uid' => $this->opr_uid]);
     $query->andFilterWhere(['like', 'svr_name', $this->svr_name])->andFilterWhere(['like', 'svr_alias', $this->svr_alias])->andFilterWhere(['like', 'svr_path', $this->svr_path])->andFilterWhere(['like', 'run_user', $this->run_user])->andFilterWhere(['like', 'comment', $this->comment]);
     return $dataProvider;
 }
 /**
  * Lists all DcmdServicePoolNode models.
  * @return mixed
  */
 public function actionIndex()
 {
     $params = array();
     if (array_key_exists('DcmdServicePoolNodeSearch', Yii::$app->request->queryParams)) {
         $params['DcmdServicePoolNodeSearch'] = Yii::$app->request->queryParams['DcmdServicePoolNodeSearch'];
         if ($params['DcmdServicePoolNodeSearch']['app_id'] == "") {
             $params['DcmdServicePoolNodeSearch']['svr_id'] = "";
         }
         if ($params['DcmdServicePoolNodeSearch']['svr_id'] == "") {
             $params['DcmdServicePoolNodeSearch']['svr_pool_id'] = "";
         }
     }
     ///应用足用户只可查看所在组的应用
     $app_con = "";
     if (Yii::$app->user->getIdentity()->admin != 1) {
         $app_con = "svr_gid in (0";
         $query = DcmdUserGroup::find()->andWhere(['uid' => Yii::$app->user->getId()])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $app_con .= "," . $item['gid'];
             }
         }
         $app_con .= ")";
     }
     $query = DcmdApp::find()->where($app_con)->orderBy('app_name')->asArray()->all();
     $app = array();
     foreach ($query as $item) {
         $app[$item['app_id']] = $item['app_alias'];
     }
     $svr = array();
     if (array_key_exists('DcmdServicePoolNodeSearch', $params) && array_key_exists('app_id', $params['DcmdServicePoolNodeSearch'])) {
         $query = DcmdService::find()->andWhere(['app_id' => $params['DcmdServicePoolNodeSearch']['app_id']])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $svr[$item['svr_id']] = $item['svr_name'];
             }
         }
         if (!array_key_exists($params['DcmdServicePoolNodeSearch']['svr_id'], $svr)) {
             $params['DcmdServicePoolNodeSearch']['svr_id'] = "";
         }
     }
     $svr_pool = array();
     if (array_key_exists('DcmdServicePoolNodeSearch', $params) && array_key_exists('svr_id', $params['DcmdServicePoolNodeSearch']) && array_key_exists($params['DcmdServicePoolNodeSearch']['svr_id'], $svr)) {
         $query = DcmdServicePool::find()->andWhere(['svr_id' => $params['DcmdServicePoolNodeSearch']['svr_id']])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $svr_pool[$item['svr_pool_id']] = $item['svr_pool'];
             }
         }
     }
     if (array_key_exists('DcmdServicePoolNodeSearch', $params)) {
         if (!array_key_exists($params['DcmdServicePoolNodeSearch']['svr_pool_id'], $svr_pool)) {
             $params['DcmdServicePoolNodeSearch']['svr_pool_id'] = "";
         }
     }
     $searchModel = new DcmdServicePoolNodeSearch();
     $dataProvider = $searchModel->search($params);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'app' => $app, 'svr' => $svr, 'svr_pool' => $svr_pool]);
 }
 public function actionGetServices()
 {
     $app_id = Yii::$app->request->post()["app_id"];
     $query = DcmdService::find()->andWhere(['app_id' => $app_id])->asArray()->all();
     $retcontent = "";
     if ($query) {
         foreach ($query as $item) {
             $retcontent .= $item["svr_id"] . "," . $item['svr_name'] . ";";
         }
     }
     echo $retcontent;
     exit;
 }
 public function actionDeleteAll()
 {
     if (!array_key_exists('selection', Yii::$app->request->post())) {
         Yii::$app->getSession()->setFlash('error', '未选择产品!');
         return $this->redirect(['index']);
     }
     $select = Yii::$app->request->post()['selection'];
     $suc_msg = "";
     $err_msg = "";
     foreach ($select as $k => $id) {
         $model = $this->findModel($id);
         ///判断用户所属的系统组是否和该应用相同
         $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $model['sa_gid']]);
         if ($query == NULL) {
             $err_msg .= $model->app_name . ":没有权限删除<br>";
             continue;
         }
         $node = DcmdService::find()->where(['app_id' => $id])->one();
         if ($node) {
             $err_msg .= $model->app_name . '该产品的服务非空,不可删除<br>';
             continue;
         } else {
             $suc_msg .= $model->app_name . ':删除成功<br>';
             $this->oprlog(3, "delete app:" . $model->app_name);
         }
         $this->deleteDiagram($id);
         $model->delete();
     }
     if ($suc_msg) {
         Yii::$app->getSession()->setFlash('success', $suc_msg);
     }
     if ($err_msg) {
         Yii::$app->getSession()->setFlash('error', $err_msg);
     }
     return $this->redirect(['index']);
 }