1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Server module for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-server |
6
|
|
|
* @package hipanel-module-server |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\server\controllers; |
12
|
|
|
|
13
|
|
|
use hipanel\base\CrudController; |
14
|
|
|
use hipanel\filters\EasyAccessControl; |
15
|
|
|
use hipanel\modules\finance\models\Tariff; |
16
|
|
|
use hipanel\modules\server\cart\ServerOrderProduct; |
17
|
|
|
use hipanel\modules\server\helpers\ServerHelper; |
18
|
|
|
use hipanel\modules\server\Module; |
19
|
|
|
use hiqdev\yii2\cart\actions\AddToCartAction; |
20
|
|
|
use Yii; |
21
|
|
|
use yii\web\ForbiddenHttpException; |
22
|
|
|
|
23
|
|
|
class OrderController extends CrudController |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* OrderController constructor. |
27
|
|
|
* |
28
|
|
|
* @param string $id |
29
|
|
|
* @param Module $module |
30
|
|
|
* @param array $config |
31
|
|
|
* @throws ForbiddenHttpException |
32
|
|
|
*/ |
33
|
|
|
public function __construct(string $id, Module $module, array $config = []) |
34
|
|
|
{ |
35
|
|
|
parent::__construct($id, $module, $config); |
36
|
|
|
|
37
|
|
|
if (!$module->orderIsAllowed) { |
38
|
|
|
throw new ForbiddenHttpException('Server order is not allowed'); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function behaviors() |
43
|
|
|
{ |
44
|
|
|
return array_merge(parent::behaviors(), [ |
45
|
|
|
[ |
46
|
|
|
'class' => EasyAccessControl::class, |
47
|
|
|
'actions' => [ |
48
|
|
|
'add-to-cart' => 'server.pay', |
49
|
|
|
'*' => 'server.read', |
50
|
|
|
], |
51
|
|
|
], |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function actions() |
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
|
|
'add-to-cart' => [ |
59
|
|
|
'class' => AddToCartAction::class, |
60
|
|
|
'productClass' => ServerOrderProduct::class, |
61
|
|
|
'redirectToCart' => true, |
62
|
|
|
], |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function actionOrder($id) |
67
|
|
|
{ |
68
|
|
|
$package = ServerHelper::getAvailablePackages(null, $id); |
69
|
|
|
$osImages = ServerHelper::getOsimages($package->tariff->type); |
|
|
|
|
70
|
|
|
|
71
|
|
|
return $this->render('order', [ |
72
|
|
|
'package' => $package, |
73
|
|
|
'product' => new ServerOrderProduct(['tariff_id' => $package->tariff->id]), |
74
|
|
|
'groupedOsimages' => ServerHelper::groupOsimages($osImages), |
75
|
|
|
'panels' => ServerHelper::getPanels(), |
76
|
|
|
]); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function actionIndex() |
80
|
|
|
{ |
81
|
|
|
return $this->render('index'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function actionXenSsd() |
85
|
|
|
{ |
86
|
|
|
return $this->render('xen_ssd', [ |
87
|
|
|
'packages' => ServerHelper::getAvailablePackages(Tariff::TYPE_XEN), |
88
|
|
|
'tariffTypes' => Yii::$app->params['vdsproduct'], |
89
|
|
|
]); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function actionOpenVz() |
93
|
|
|
{ |
94
|
|
|
return $this->render('open_vz', [ |
95
|
|
|
'packages' => ServerHelper::getAvailablePackages(Tariff::TYPE_OPENVZ), |
96
|
|
|
'tariffTypes' => Yii::$app->params['vdsproduct'], |
97
|
|
|
]); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function actionTariffsDetails() |
101
|
|
|
{ |
102
|
|
|
return $this->render('tariffs_details'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function actionAdvantages() |
106
|
|
|
{ |
107
|
|
|
return $this->render('advantages'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function actionWhatIsVds() |
111
|
|
|
{ |
112
|
|
|
return $this->render('what_is_vds'); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|