/**
  * Displays a single DcmdService model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     ///$query = DcmdServicePool::find()->andWhere(['svr_id'=>$id]);
     $searchModel = new DcmdServicePoolSearch();
     $con = array();
     $con['DcmdServicePoolSearch'] = array('svr_id' => $id);
     if (array_key_exists('DcmdServicePoolSearch', Yii::$app->request->queryParams)) {
         $con = array_merge($con, Yii::$app->request->queryParams);
     }
     $con['DcmdServicePoolSearch']['svr_id'] = $id;
     $dataProvider = $searchModel->search($con);
     ///处理图片
     $service = DcmdService::findOne($id);
     $base_path = dirname(__DIR__) . "/web/app_image/";
     $query = DcmdServiceArchDiagram::find()->andWhere(['svr_id' => $id, 'app_id' => $service->app_id])->asArray()->all();
     foreach ($query as $item) {
         $img_path = $base_path . "svr_" . $item['arch_name'] . '_' . $item['svr_id'] . '.jpg';
         if (file_exists($img_path)) {
             continue;
         }
         $fp = fopen($img_path, 'wb') or die("Open file {$img_path} fail!");
         fwrite($fp, stripslashes($item['diagram']));
         fclose($fp);
     }
     $imageSearch = new DcmdServiceArchDiagramSearch();
     $imageProvider = $imageSearch->search(array('DcmdServiceArchDiagramSearch' => array('app_id' => $service->app_id, 'svr_id' => $id)));
     ///获取任务模版列表
     $tmpt_searchModel = new DcmdTaskTemplateSearch();
     $params["DcmdTaskTemplateSearch"]["svr_id"] = $id;
     $taskTemptDataProvider = $tmpt_searchModel->search($params, 1000);
     return $this->render('view', ['model' => $this->findModel($id), 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'imageProvider' => $imageProvider, 'taskTemptDataProvider' => $taskTemptDataProvider]);
 }
 /**
  * Lists all DcmdServicePool models.
  * @return mixed
  */
 public function actionIndex()
 {
     $params = array();
     if (array_key_exists('DcmdServicePoolSearch', Yii::$app->request->queryParams)) {
         $params['DcmdServicePoolSearch'] = Yii::$app->request->queryParams['DcmdServicePoolSearch'];
         if ($params['DcmdServicePoolSearch']['app_id'] == "") {
             $params['DcmdServicePoolSearch']['svr_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_name'];
     }
     if (array_key_exists('DcmdServicePoolSearch', $params)) {
         if (!array_key_exists($params['DcmdServicePoolSearch']['app_id'], $app)) {
             $params['DcmdServicePoolSearch']['svr_id'] = "";
         }
     }
     $svr = array();
     if (array_key_exists('DcmdServicePoolSearch', $params) && array_key_exists('app_id', $params['DcmdServicePoolSearch'])) {
         $query = DcmdService::find()->andWhere(['app_id' => $params['DcmdServicePoolSearch']['app_id']])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $svr[$item['svr_id']] = $item['svr_name'];
             }
         }
     }
     if (array_key_exists('DcmdServicePoolSearch', $params)) {
         if (!array_key_exists($params['DcmdServicePoolSearch']['svr_id'], $svr)) {
             $params['DcmdServicePoolSearch']['svr_id'] = "";
         }
     }
     $searchModel = new DcmdServicePoolSearch();
     $dataProvider = $searchModel->search($params);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'app' => $app, 'svr' => $svr]);
 }