Commit e2af367e3e36ec71642447411a06ef93d7691f6e
1 parent
17569d93
-Order product log beta test
Showing
4 changed files
with
296 additions
and
140 deletions
Show diff stats
controllers/OrderController.php
... | ... | @@ -4,7 +4,6 @@ |
4 | 4 | |
5 | 5 | use artweb\artbox\components\SmsSender; |
6 | 6 | use artweb\artbox\ecommerce\models\OrderLabelHistory; |
7 | - use artweb\artbox\ecommerce\models\OrderLog; | |
8 | 7 | use artweb\artbox\ecommerce\models\OrderSearch; |
9 | 8 | use common\components\CreditHelper; |
10 | 9 | use common\models\User; |
... | ... | @@ -151,7 +150,24 @@ |
151 | 150 | |
152 | 151 | $productLogData = new ActiveDataProvider( |
153 | 152 | [ |
154 | - 'query' => $model->getProductLogs(), | |
153 | + 'query' => $model->getProducts() | |
154 | + ->with([ | |
155 | + 'logs' => function(ActiveQuery $query) { | |
156 | + $query->with('user'); | |
157 | + }, | |
158 | + 'productVariant' => function(ActiveQuery $query) { | |
159 | + $query->with([ | |
160 | + 'lang', | |
161 | + 'product' => function(ActiveQuery $query) { | |
162 | + $query->with([ | |
163 | + 'lang', | |
164 | + 'category.lang', | |
165 | + 'brand.lang', | |
166 | + ]); | |
167 | + } | |
168 | + ]); | |
169 | + }, | |
170 | + ]), | |
155 | 171 | ] |
156 | 172 | ); |
157 | 173 | |
... | ... | @@ -175,17 +191,6 @@ |
175 | 191 | return $this->redirect([ 'index' ]); |
176 | 192 | } |
177 | 193 | |
178 | - // public function actionDeleteProduct($id) | |
179 | - // { | |
180 | - // $model = OrderProduct::findOne($id); | |
181 | - // $model->removed = true; | |
182 | - // $orderId = $model->order_id; | |
183 | - // if ($model->save()) { | |
184 | - // $model->order->totalRecount(); | |
185 | - // return $this->actionUpdate($orderId); | |
186 | - // } | |
187 | - // } | |
188 | - | |
189 | 194 | public function actionAdd() |
190 | 195 | { |
191 | 196 | if (!empty(\Yii::$app->request->post())) { |
... | ... | @@ -285,26 +290,26 @@ |
285 | 290 | ] |
286 | 291 | ); |
287 | 292 | |
288 | - $dataProvider = new ActiveDataProvider( | |
289 | - [ | |
290 | - 'query' => $model->getProducts() | |
291 | - ->joinWith('productVariant'), | |
292 | - ] | |
293 | - ); | |
294 | - | |
295 | - if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
296 | - $model->published = true; | |
297 | - $model->save(); | |
298 | - return $this->redirect([ 'index' ]); | |
299 | - } else { | |
300 | - return $this->render( | |
301 | - 'create', | |
302 | - [ | |
303 | - 'model' => $model, | |
304 | - 'dataProvider' => $dataProvider, | |
305 | - ] | |
306 | - ); | |
307 | - } | |
293 | + // $dataProvider = new ActiveDataProvider( | |
294 | + // [ | |
295 | + // 'query' => $model->getProducts() | |
296 | + // ->joinWith('productVariant'), | |
297 | + // ] | |
298 | + // ); | |
299 | + // | |
300 | + // if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
301 | + // $model->published = true; | |
302 | + // $model->save(); | |
303 | + // return $this->redirect([ 'index' ]); | |
304 | + // } else { | |
305 | + // return $this->render( | |
306 | + // 'create', | |
307 | + // [ | |
308 | + // 'model' => $model, | |
309 | + // 'dataProvider' => $dataProvider, | |
310 | + // ] | |
311 | + // ); | |
312 | + // } | |
308 | 313 | } |
309 | 314 | |
310 | 315 | public function actionPrint($order_id) |
... | ... | @@ -442,7 +447,7 @@ |
442 | 447 | |
443 | 448 | public function actionFindProduct($q = NULL, $id = NULL) |
444 | 449 | { |
445 | - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |
450 | + \Yii::$app->response->format = Response::FORMAT_JSON; | |
446 | 451 | $out = [ |
447 | 452 | 'results' => [ |
448 | 453 | 'id' => '', |
... | ... | @@ -450,13 +455,7 @@ |
450 | 455 | ], |
451 | 456 | ]; |
452 | 457 | if (!is_null($q)) { |
453 | - $result = ProductVariant::find()// ->select( | |
454 | - // [ | |
455 | - // 'id', | |
456 | - // 'sku', | |
457 | - // 'product_lang.title AS name' | |
458 | - // ] | |
459 | - // ) | |
458 | + $result = ProductVariant::find() | |
460 | 459 | ->joinWith('product.lang') |
461 | 460 | ->where( |
462 | 461 | [ |
... | ... | @@ -491,7 +490,7 @@ |
491 | 490 | $model->save(); |
492 | 491 | $order = Order::findOne($order_id); |
493 | 492 | $order->totalRecount(); |
494 | - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |
493 | + \Yii::$app->response->format = Response::FORMAT_JSON; | |
495 | 494 | return [ |
496 | 495 | 'status' => 'success', |
497 | 496 | 'id' => $id, |
... | ... | @@ -521,7 +520,6 @@ |
521 | 520 | if (!$model->published) { |
522 | 521 | $model->deleteUnpublished(); |
523 | 522 | } |
524 | - // return $this->redirect('index'); | |
525 | 523 | } |
526 | 524 | |
527 | 525 | public function actionCloseOrder($id) | ... | ... |
models/OrderProduct.php
... | ... | @@ -9,21 +9,22 @@ |
9 | 9 | /** |
10 | 10 | * Class OrderProduct |
11 | 11 | * |
12 | - * @property int $id | |
13 | - * @property int $order_id | |
14 | - * @property int $product_variant_id | |
15 | - * @property string $booking | |
16 | - * @property string $status | |
17 | - * @property boolean $return | |
18 | - * @property string $product_name | |
19 | - * @property string $name | |
20 | - * @property string $sku | |
21 | - * @property double $price | |
22 | - * @property int $count | |
23 | - * @property double $sum_cost | |
24 | - * @property Order $order | |
25 | - * @property boolean $removed | |
26 | - * @property ProductVariant $productVariant | |
12 | + * @property int $id | |
13 | + * @property int $order_id | |
14 | + * @property int $product_variant_id | |
15 | + * @property string $booking | |
16 | + * @property string $status | |
17 | + * @property boolean $return | |
18 | + * @property string $product_name | |
19 | + * @property string $name | |
20 | + * @property string $sku | |
21 | + * @property double $price | |
22 | + * @property int $count | |
23 | + * @property double $sum_cost | |
24 | + * @property Order $order | |
25 | + * @property boolean $removed | |
26 | + * @property OrderProductLog[] $logs | |
27 | + * @property ProductVariant $productVariant | |
27 | 28 | * @package artweb\artbox\ecommerce\models |
28 | 29 | */ |
29 | 30 | class OrderProduct extends ActiveRecord |
... | ... | @@ -99,9 +100,16 @@ |
99 | 100 | 'return' => Yii::t('app', 'Возврат'), |
100 | 101 | 'sku' => Yii::t('app', 'Артикул'), |
101 | 102 | 'price' => Yii::t('app', 'Цена'), |
103 | + 'order_id' => Yii::t('app', 'Id заказа'), | |
104 | + 'product_variant_id' => Yii::t('app', 'Id товара'), | |
105 | + 'id' => Yii::t('app', 'Id'), | |
106 | + 'removed' => Yii::t('app', 'Удален'), | |
102 | 107 | ]; |
103 | 108 | } |
104 | 109 | |
110 | + /** | |
111 | + * @return \yii\db\ActiveQuery | |
112 | + */ | |
105 | 113 | public function getOrder() |
106 | 114 | { |
107 | 115 | return $this->hasOne(Order::className(), [ 'id' => 'order_id' ]); |
... | ... | @@ -114,4 +122,12 @@ |
114 | 122 | { |
115 | 123 | return $this->hasOne(ProductVariant::className(), [ 'id' => 'product_variant_id' ]); |
116 | 124 | } |
125 | + | |
126 | + /** | |
127 | + * @return \yii\db\ActiveQuery | |
128 | + */ | |
129 | + public function getLogs() | |
130 | + { | |
131 | + return $this->hasMany(OrderProductLog::className(), [ 'order_product_id' => 'id' ]); | |
132 | + } | |
117 | 133 | } |
118 | 134 | \ No newline at end of file | ... | ... |
views/order/_log_product_item.php
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @var OrderProductLog $model | |
4 | - * @var Order $order | |
3 | + * @var OrderProduct $model | |
4 | + * @var Order $order | |
5 | 5 | */ |
6 | 6 | use artweb\artbox\ecommerce\models\Order; |
7 | + use artweb\artbox\ecommerce\models\OrderProduct; | |
7 | 8 | use artweb\artbox\ecommerce\models\OrderProductLog; |
8 | 9 | use yii\helpers\Html; |
9 | 10 | use yii\helpers\Json; |
11 | + use yii\helpers\StringHelper; | |
12 | + use yii\helpers\Url; | |
10 | 13 | |
11 | 14 | ?> |
15 | +<div class="box box-success"> | |
16 | + <div class="box-header with-border"> | |
17 | + <h3 class="box-title">История товара <a href="<?=Url::to( | |
18 | + [ | |
19 | + '/ecommerce/variant/view', | |
20 | + 'product_id' => $model->productVariant->product->id, | |
21 | + 'id' => $model->productVariant->id, | |
22 | + ] | |
23 | + ) ?>" target="_blank" class="text-green"><?php echo $model->sku; ?></a></h3> | |
24 | + <div class="box-tools pull-right"> | |
25 | + <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i> | |
26 | + </button> | |
27 | + </div> | |
28 | + </div> | |
29 | + <div class="box-body row"> | |
12 | 30 | |
13 | -<!-- timeline item --> | |
14 | -<li> | |
15 | - <!-- timeline icon --> | |
16 | - <i class="fa fa-user bg-green"></i> | |
17 | - <div class="timeline-item"> | |
18 | - <span class="time"><i class="fa fa-calendar"></i> <?= Yii::$app->formatter->asDatetime($model->created_at) ?></span> | |
19 | - | |
20 | - <h3 class="timeline-header">Пользователь: <span class="text-green"><?= $model->user->username ?></span></h3> | |
21 | - | |
22 | - <div class="timeline-body"> | |
23 | - <table class="table table-bordered table-striped"> | |
24 | - <tr> | |
25 | - <th>Поле</th> | |
26 | - <th>Старое значение</th> | |
27 | - <th>Новое значение</th> | |
28 | - </tr> | |
29 | - <?php | |
30 | - foreach (Json::decode($model->data) as $key => $item) { | |
31 | - echo Html::tag( | |
32 | - 'tr', | |
33 | - Html::tag('td', $key ) . Html::tag('td', $item[ 'old' ]) . Html::tag( | |
34 | - 'td', | |
35 | - $item[ 'new' ] | |
36 | - ) | |
37 | - ); | |
38 | - } | |
39 | - ?> | |
40 | - </table> | |
31 | + <div class="col-md-4 col-sm-12 col-xs-12"> | |
32 | + <?php | |
33 | + echo Html::tag('h3', $model->product_name); | |
34 | + if (empty($model->productVariant)) { | |
35 | + echo ''; | |
36 | + } else { | |
37 | + echo Html::img( | |
38 | + $model->productVariant->imageUrl, | |
39 | + [ | |
40 | + 'class' => 'img-thumbnail', | |
41 | + ] | |
42 | + ); | |
43 | + } | |
44 | + echo Html::beginTag('br'); | |
45 | + ?> | |
41 | 46 | </div> |
42 | 47 | |
43 | - </div> | |
44 | -</li> | |
48 | + <div class="col-md-4 col-sm-12 col-xs-12"> | |
49 | + <div class="info-box"> | |
50 | + <span class="info-box-icon bg-green"><i class="fa fa-shopping-basket "></i></span> | |
51 | + <div class="info-box-content"> | |
52 | + <span style="text-decoration: line-through" class="info-box-text"><?= !empty($model->productVariant->price_old) ? $model->productVariant->price_old : '' ?></span> | |
53 | + <span class="info-box-number"><?= $model->productVariant->price ?> грн.</span> | |
54 | + </div> | |
55 | + <!-- /.info-box-content --> | |
56 | + </div> | |
57 | + <div class="box-footer no-padding"> | |
58 | + <ul class="nav nav-stacked"> | |
59 | + <li><a target="_blank" href="<?= Url::to( | |
60 | + [ | |
61 | + '/ecommerce/manage/view', | |
62 | + 'id' => $model->productVariant->product->id, | |
63 | + ] | |
64 | + ) ?>">Название: <span class="text-orange pull-right"><?php echo StringHelper::truncate( | |
65 | + $model->productVariant->product->lang->title, | |
66 | + 35, | |
67 | + '...' | |
68 | + ); ?></span></a></li> | |
69 | + <li><a target="_blank" href="<?= Url::to( | |
70 | + [ | |
71 | + '/ecommerce/category/view', | |
72 | + 'id' => $model->productVariant->category->id, | |
73 | + ] | |
74 | + ) ?>">Категория: | |
75 | + <span class="pull-right text-orange"><?php echo $model->productVariant->category->lang->title; ?></span></a> | |
76 | + </li> | |
77 | + <li><a target="_blank" href="<?= Url::to( | |
78 | + [ | |
79 | + '/ecommerce/brand/view', | |
80 | + 'id' => $model->productVariant->product->brand->id, | |
81 | + ] | |
82 | + ) ?>">Брэнд: | |
83 | + <span class="pull-right text-orange"><?php echo $model->productVariant->product->brand->lang->title; ?></span></a> | |
84 | + </li> | |
85 | + <li><a target="_blank" href="#">Метки: | |
86 | + <?php | |
87 | + if ($model->productVariant->product->is_discount) { | |
88 | + echo Html::tag( | |
89 | + 'span', | |
90 | + 'Акция', | |
91 | + [ | |
92 | + 'class' => 'pull-right badge bg-red', | |
93 | + ] | |
94 | + ); | |
95 | + } | |
96 | + if ($model->productVariant->product->is_top) { | |
97 | + echo Html::tag( | |
98 | + 'span', | |
99 | + 'Топ', | |
100 | + [ | |
101 | + 'class' => 'pull-right badge bg-purple', | |
102 | + ] | |
103 | + ); | |
104 | + } | |
105 | + if ($model->productVariant->product->is_new) { | |
106 | + echo Html::tag( | |
107 | + 'span', | |
108 | + 'Новый', | |
109 | + [ | |
110 | + 'class' => 'pull-right badge bg-blue', | |
111 | + ] | |
112 | + ); | |
113 | + } | |
114 | + ?> | |
115 | + | |
116 | + </a></li> | |
117 | + </ul> | |
118 | + </div> | |
119 | + | |
120 | + </div> | |
121 | + | |
122 | + <div class="col-md-4 col-sm-12 col-xs-12"> | |
123 | + <?php if (!empty($model->logs)) { | |
124 | + echo Html::beginTag( | |
125 | + 'ul', | |
126 | + [ | |
127 | + 'class' => 'timeline', | |
128 | + ] | |
129 | + ); | |
130 | + foreach ($model->logs as $log) { | |
131 | + /** | |
132 | + * @var OrderProductLog $log | |
133 | + */ | |
134 | + $data = Json::decode($log->data); ?> | |
135 | + | |
136 | + <li> | |
137 | + <i class="fa fa-pencil bg-blue"></i> | |
138 | + <div class="timeline-item"> | |
139 | + <span class="time"><i class="fa fa-calendar"></i> <?= \Yii::$app->formatter->asDatetime( | |
140 | + $log->created_at | |
141 | + ) ?></span> | |
142 | + | |
143 | + <h3 class="timeline-header"><?php | |
144 | + echo empty($log->user) ? Html::tag( | |
145 | + 'span', | |
146 | + 'Добавлен с сайта', | |
147 | + [ 'class' => 'text-orange' ] | |
148 | + ) : 'Пользователь: ' . Html::tag('span', $log->user->username, [ 'class' => 'text-blue' ]) ?> | |
149 | + </h3> | |
150 | + <?php | |
151 | + if (isset($data[ 'removed' ])) { | |
152 | + ?> | |
153 | + <div class="timeline-body"> | |
154 | + <span class="text-red">Товар удален</span> | |
155 | + </div> | |
156 | + <?php | |
157 | + } elseif (isset($data[ 'id' ])) { | |
158 | + ?> | |
159 | + <div class="timeline-body"> | |
160 | + <span class="text-green">Товар добавлен</span> | |
161 | + </div> | |
162 | + <?php | |
163 | + } else { | |
164 | + ?> | |
165 | + <div class="timeline-body"> | |
166 | + <ul class="products-list product-list-in-box"> | |
167 | + <?php foreach ($data as $key => $item) { | |
168 | + echo Html::tag( | |
169 | + 'li', | |
170 | + $model->attributeLabels()[ $key ] . ' > ' . Html::tag( | |
171 | + 'span', | |
172 | + \Yii::$app->formatter->asText($item[ 'old' ]), | |
173 | + [ 'class' => 'text-red' ] | |
174 | + ) . ' > ' . Html::tag('span', | |
175 | + \Yii::$app->formatter->asText($item[ 'new' ]), | |
176 | + [ 'class' => 'text-green' ]), | |
177 | + [ 'class' => 'item' ] | |
178 | + ); | |
179 | + } ?> | |
180 | + </ul> | |
181 | + </div> | |
182 | + <?php | |
183 | + } | |
184 | + ?> | |
185 | + </div> | |
186 | + </li> | |
187 | + <?php | |
188 | + } | |
189 | + echo Html::endTag('ul'); | |
190 | + } | |
191 | + ?> | |
192 | + </div> | |
193 | + | |
194 | + </div><!-- /.box-body --> | |
195 | +</div><!-- /.box --> | ... | ... |
views/order/log.php
... | ... | @@ -18,51 +18,19 @@ |
18 | 18 | 'label' => \Yii::t('app', 'Заказы'), |
19 | 19 | ]; |
20 | 20 | $this->params[ 'breadcrumbs' ][] = [ |
21 | - 'url' => yii\helpers\Url::to([ '/ecommerce/order/view', 'id' => $model->id ]), | |
21 | + 'url' => yii\helpers\Url::to( | |
22 | + [ | |
23 | + '/ecommerce/order/view', | |
24 | + 'id' => $model->id, | |
25 | + ] | |
26 | + ), | |
22 | 27 | 'label' => \Yii::t('app', 'Заказ #') . $model->id, |
23 | 28 | ]; |
24 | 29 | $this->params[ 'breadcrumbs' ][] = $this->title; |
25 | - | |
30 | + | |
26 | 31 | ?> |
27 | 32 | |
28 | 33 | <div class="order-log"> |
29 | - | |
30 | - <div class="box box-default"> | |
31 | - <div class="box-header with-border"> | |
32 | - <h3 class="box-title">История</h3> | |
33 | - <div class="box-tools pull-right"> | |
34 | - <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i> | |
35 | - </button> | |
36 | - </div> | |
37 | - </div> | |
38 | - <div class="box-body"> | |
39 | - | |
40 | - <?php | |
41 | - echo ListView::widget( | |
42 | - [ | |
43 | - 'dataProvider' => $logData, | |
44 | - 'layout' => '{items}', | |
45 | - 'itemView' => '_log_item', | |
46 | - 'itemOptions' => [ | |
47 | - 'tag' => false, | |
48 | - ], | |
49 | - 'options' => [ | |
50 | - 'tag' => $logData->totalCount == 0 ? 'div' : 'ul', | |
51 | - 'class' => $logData->totalCount == 0 ? 'list-view' : 'list-view timeline', | |
52 | - ], | |
53 | - 'viewParams' => [ | |
54 | - 'order' => $model, | |
55 | - ], | |
56 | - 'emptyText' => 'У этого заказа пока нет истории', | |
57 | - 'emptyTextOptions' => [ | |
58 | - 'class' => 'callout callout-info' | |
59 | - ], | |
60 | - ] | |
61 | - ); | |
62 | - ?> | |
63 | - | |
64 | - </div><!-- /.box-body --> | |
65 | - </div><!-- /.box --> | |
66 | 34 | |
67 | 35 | <div class="box box-default"> |
68 | 36 | <div class="box-header with-border"> |
... | ... | @@ -77,22 +45,22 @@ |
77 | 45 | <?php |
78 | 46 | echo ListView::widget( |
79 | 47 | [ |
80 | - 'dataProvider' => $productLogData, | |
81 | - 'layout' => '{items}', | |
82 | - 'itemView' => '_log_product_item', | |
83 | - 'itemOptions' => [ | |
48 | + 'dataProvider' => $logData, | |
49 | + 'layout' => '{items}', | |
50 | + 'itemView' => '_log_item', | |
51 | + 'itemOptions' => [ | |
84 | 52 | 'tag' => false, |
85 | 53 | ], |
86 | - 'options' => [ | |
87 | - 'tag' => $productLogData->totalCount == 0 ? 'div' : 'ul', | |
88 | - 'class' => $productLogData->totalCount == 0 ? 'list-view' : 'list-view timeline', | |
54 | + 'options' => [ | |
55 | + 'tag' => $logData->totalCount == 0 ? 'div' : 'ul', | |
56 | + 'class' => $logData->totalCount == 0 ? 'list-view' : 'list-view timeline', | |
89 | 57 | ], |
90 | - 'viewParams' => [ | |
58 | + 'viewParams' => [ | |
91 | 59 | 'order' => $model, |
92 | 60 | ], |
93 | - 'emptyText' => 'У этого заказа пока нет истории', | |
61 | + 'emptyText' => 'У этого заказа пока нет истории', | |
94 | 62 | 'emptyTextOptions' => [ |
95 | - 'class' => 'callout callout-info' | |
63 | + 'class' => 'callout callout-info', | |
96 | 64 | ], |
97 | 65 | ] |
98 | 66 | ); |
... | ... | @@ -100,5 +68,28 @@ |
100 | 68 | |
101 | 69 | </div><!-- /.box-body --> |
102 | 70 | </div><!-- /.box --> |
103 | - | |
71 | + | |
72 | + <?php | |
73 | + echo ListView::widget( | |
74 | + [ | |
75 | + 'dataProvider' => $productLogData, | |
76 | + 'layout' => '{items}', | |
77 | + 'itemView' => '_log_product_item', | |
78 | + 'itemOptions' => [ | |
79 | + 'tag' => false, | |
80 | + ], | |
81 | + 'viewParams' => [ | |
82 | + 'order' => $model, | |
83 | + ], | |
84 | + 'options' => [ | |
85 | + 'class' => 'list-view', | |
86 | + ], | |
87 | + 'emptyText' => 'У этого заказа нет товаров', | |
88 | + 'emptyTextOptions' => [ | |
89 | + 'class' => 'callout callout-info', | |
90 | + ], | |
91 | + ] | |
92 | + ); | |
93 | + ?> | |
94 | + | |
104 | 95 | </div> | ... | ... |