Exemplo n.º 1
0
 /**
  * Creates a new Ip model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Ip();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Ip model.
  * 创建一个新的IP绑定,并且将绑定数据存入数据库
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Ip();
     if ($post = Yii::$app->request->post()) {
         $model->load(Yii::$app->request->post());
         $telnet = new telnet();
         $loginMsg = $telnet->signin();
         $telnet->bind($model->ip, $model->mac);
         $telnet->close();
         $model->save();
         if ($model->type == 3) {
             return $this->redirect(['charge', 'ip' => $model->ip]);
         } else {
             return $this->redirect(['index']);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 3
0
 public function actionProductRating()
 {
     if (Yii::$app->request->isAjax and $rating = Yii::$app->request->post('rating') and $id = Yii::$app->request->post('id')) {
         if ($product = Product::findOne($id)) {
             $ip = Yii::$app->request->userIP;
             $ipModel = Ip::find()->where(['name' => $ip, 'product_id' => $id])->one();
             if ($ipModel === null) {
                 $currentRating = $product->rating;
                 $currentRatingCount = $product->rating_count;
                 $resultRating = round(($currentRating + $rating) / 2, 1);
                 $product->rating = $resultRating;
                 $product->rating_count = $currentRatingCount + 1;
                 $product->save();
                 $model = new Ip();
                 $model->name = $ip;
                 $model->product_id = $id;
                 $model->save();
                 return true;
             } else {
                 return 'forbidden';
                 // $this->refresh();
             }
         } else {
             return false;
         }
         // return json_encode([$rating, $id]);
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }