ecf49b1b
Administrator
second
|
1
2
3
4
5
6
7
8
9
10
11
|
<?php
namespace frontend\controllers;
use Yii;
use yii\web\Controller;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\data\ActiveDataProvider;
use yii\data\Pagination;
use common\models\User;
|
7d9935e2
Administrator
проапдейтил роли
|
12
|
use common\models\Orders;
|
ecf49b1b
Administrator
second
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
use common\models\OrdersProducts;
use common\models\Share;
use common\models\Price;
class IamController extends Controller
{
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
//'only' => ['person'],
'rules' => [
[
'actions' => ['index','edit','myorders','show_order','share','price'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
public function actionIndex()
{
|
ecf49b1b
Administrator
second
|
47
|
return $this->render(Yii::$app->user->identity->role, [
|
7ba4acc5
Administrator
after marge
|
48
|
'model' => Yii::$app->user->identity,
|
ecf49b1b
Administrator
second
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
]);
}
public function actionEdit()
{
$model = User::findOne(Yii::$app->user->id);
$model->scenario = 'edit_'.Yii::$app->user->identity->role;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return Yii::$app->response->redirect(['/iam/index']);
}
return $this->render('edit_'.Yii::$app->user->identity->role, [
'model' => $model,
]);
}
public function actionMyorders(){
|
7d9935e2
Administrator
проапдейтил роли
|
75
|
$model = Orders::find()->where(['user_id'=>Yii::$app->user->id])->orderBy('id DESC')->all();
|
ecf49b1b
Administrator
second
|
76
77
78
79
80
81
82
|
return $this->render('myorders',['model'=>$model]);
}
public function actionShow_order()
{
|
7d9935e2
Administrator
проапдейтил роли
|
83
|
$model = Orders::findOne($_GET['id']);
|
ecf49b1b
Administrator
second
|
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
$dataProvider = new ActiveDataProvider([
'query' => OrdersProducts::find()->where(['order_id'=>$_GET['id']]),
'pagination' => [
'pageSize' => 20,
],
]);
return $this->render('show_order',['model'=>$model,'dataProvider'=>$dataProvider]);
}
public function actionShare(){
if(!empty($_GET['id'])){
if(!$model = Share::find()->where('user_id=:user_id and product_id=:product_id',[':user_id'=>Yii::$app->user->id,':product_id'=>$_GET['id']])->one())
$model = new Share;
$model->product_id = $_GET['id'];
$model->save();
Yii::$app->getSession()->setFlash('success', 'Этот товар добавлен в закладку!');
return $this->redirect(Yii::$app->request->referrer);
}
else{
/* $dataProvider = new ActiveDataProvider([
'query' => Share::find()->where(['user_id'=>Yii::$app->user->id])->orderBy('date_time DESC'),
'pagination' => [
'pageSize' => 20,
],
]);*/
if(!empty($_GET['deleteID'])){
$model = Share::find()->where(['user_id'=>Yii::$app->user->id,'id'=>$_GET['deleteID']])->one();
$model->delete();
return $this->redirect(Yii::$app->request->referrer);
}
$query = Share::find()->where(['user_id'=>Yii::$app->user->id])->groupBy('date')->orderBy('date DESC');
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize'=>20]);
$pages->forcePageParam = false;
$pages->pageSizeParam = false;
$share = $query->offset($pages->offset)
->limit($pages->limit)
->all();
return $this->render('share',['share'=>$share,'pages'=>$pages]);
}
}
public function actionPrice(){
if(!empty($_GET['id'])){
if(!$model = Price::find()->where('user_id=:user_id and product_id=:product_id',[':user_id'=>Yii::$app->user->id,':product_id'=>$_GET['id']])->one())
$model = new Price;
$model->product_id = $_GET['id'];
$model->save();
Yii::$app->getSession()->setFlash('success', 'Этот товар добавлен в закладку Узнать о снижение цены!');
return $this->redirect(Yii::$app->request->referrer);
}
else{
$dataProvider = new ActiveDataProvider([
'query' => Price::find()->where(['user_id'=>Yii::$app->user->id])->orderBy('date_time DESC'),
'pagination' => [
'pageSize' => 20,
],
]);
return $this->render('price',['dataProvider'=>$dataProvider]);
}
}
}
|