public function actionGenerarcupon($id)
 {
     $cupon = new Cupones();
     $request = Yii::$app->request;
     $cupon->idusuario = \Yii::$app->user->identity->id;
     $cupon->idproducto = $id;
     $hoy = date('Y-m-d');
     $cupon->fecha = $hoy;
     $producto = Productos::findOne($id);
     $producto->vendidos += 1;
     $cupon->save();
     $producto->update();
     $Models = Stock::findOne($id);
     if ($Models != null) {
         $Models->stock--;
         if ($Models == 0) {
             $producto = Productos::findOne($id);
             $producto->activo = 0;
         }
         $Models->save();
     }
     return $this->redirect(['view', 'id' => $cupon->id]);
 }
 /**
  * Finds the Productos model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Productos the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Productos::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }