/**
  * @param string $type (svds|ovds)
  * @param integer $tariff_id
  * @throws NotFoundHttpException
  * @throws UnprocessableEntityHttpException
  * @return Package|array
  */
 public static function getAvailablePackages($type = null, $tariff_id = null)
 {
     $cacheKeys = [Yii::$app->params['user.seller'], Yii::$app->user->id, $type, $tariff_id, 'tariffs'];
     /** @var Tariff[] $tariffs */
     $tariffs = Yii::$app->getCache()->getTimeCached(3600, $cacheKeys, function ($seller, $client_id, $type, $tariff_id) {
         return Tariff::find(['scenario' => 'get-available-info'])->details()->andWhere(['seller' => $seller])->andFilterWhere(['id' => $tariff_id])->andFilterWhere(['type' => $type])->all();
     });
     $cacheKeys = [Yii::$app->params['user.seller'], Yii::$app->user->id, $type, $tariff_id, 'tariffs', 'packages'];
     /** @var Package[] $packages */
     $packages = Yii::$app->getCache()->getTimeCached(3600, $cacheKeys, function () use($tariffs) {
         $calculator = new Calculator($tariffs);
         $packages = [];
         foreach ($tariffs as $tariff) {
             $calculation = $calculator->getCalculation($tariff->id);
             $packages[] = Yii::createObject(['class' => static::buildPackageClass($tariff), 'tariff' => $tariff, 'calculation' => $calculation]);
         }
         return $packages;
     });
     ArrayHelper::multisort($packages, 'price', SORT_ASC, SORT_NUMERIC);
     if (empty($packages)) {
         throw new NotFoundHttpException('Requested tariff is not available');
     }
     if (isset($tariff_id) && !is_array($tariff_id)) {
         return reset($packages);
     }
     return $packages;
 }
 /**
  * @inheritdoc
  */
 public function execute()
 {
     parent::execute();
     $this->applyCalculations();
     return $this->calculations;
 }