Commit ff71eeed3b9c1ccb76d72a0d91b0c2211bf34f7d
1 parent
6649cf43
-Logs ready
Showing
5 changed files
with
134 additions
and
51 deletions
Show diff stats
models/Order.php
| @@ -129,24 +129,72 @@ | @@ -129,24 +129,72 @@ | ||
| 129 | return $result; | 129 | return $result; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | + /** | ||
| 133 | + * @param string $attr | ||
| 134 | + * @param array $values | ||
| 135 | + * | ||
| 136 | + * @return array | ||
| 137 | + * Return array in form ['old'=>'old value ...', 'new' => 'new value ...'] | ||
| 138 | + */ | ||
| 132 | public function getLogAttributes(string $attr, array $values) | 139 | public function getLogAttributes(string $attr, array $values) |
| 133 | { | 140 | { |
| 134 | - $labels = Label::find()->with('lang')->indexBy('id')->all(); | ||
| 135 | if ($attr == 'deadline') { | 141 | if ($attr == 'deadline') { |
| 136 | return [ | 142 | return [ |
| 137 | - 'old' => empty($values['old']) ? '' : date('d.m.Y', $values['old']), | ||
| 138 | - 'new' => empty($values['new']) ? '' : date('d.m.Y', $values['new']), | 143 | + 'old' => empty($values[ 'old' ]) ? '' : date('d.m.Y', $values[ 'old' ]), |
| 144 | + 'new' => empty($values[ 'new' ]) ? '' : date('d.m.Y', $values[ 'new' ]), | ||
| 145 | + ]; | ||
| 146 | + } elseif ($attr == 'reason') { | ||
| 147 | + return [ | ||
| 148 | + 'old' => empty($values[ 'old' ]) ? '' : self::REASONS[ $values[ 'old' ] ], | ||
| 149 | + 'new' => empty($values[ 'new' ]) ? '' : self::REASONS[ $values[ 'new' ] ], | ||
| 150 | + ]; | ||
| 151 | + } elseif ($attr == 'label') { | ||
| 152 | + $labels = Label::find() | ||
| 153 | + ->with('lang') | ||
| 154 | + ->indexBy('id') | ||
| 155 | + ->all(); | ||
| 156 | + return [ | ||
| 157 | + 'old' => empty($values[ 'old' ]) ? '' : $labels[ $values[ 'old' ] ]->lang->title, | ||
| 158 | + 'new' => empty($values[ 'new' ]) ? '' : $labels[ $values[ 'new' ] ]->lang->title, | ||
| 139 | ]; | 159 | ]; |
| 140 | - } elseif ($attr = 'reason') { | 160 | + } elseif ($attr == 'delivery') { |
| 161 | + $deliveries = Delivery::find() | ||
| 162 | + ->with('lang') | ||
| 163 | + ->indexBy('id') | ||
| 164 | + ->all(); | ||
| 141 | return [ | 165 | return [ |
| 142 | - 'old' => empty($values['old']) ? '' : self::REASONS[$values['old']], | ||
| 143 | - 'new' => empty($values['new']) ? '' : self::REASONS[$values['new']], | 166 | + 'old' => empty($values[ 'old' ]) ? '' : $deliveries[ $values[ 'old' ] ]->lang->title, |
| 167 | + 'new' => empty($values[ 'new' ]) ? '' : $deliveries[ $values[ 'new' ] ]->lang->title, | ||
| 144 | ]; | 168 | ]; |
| 145 | - } elseif ($attr = 'label') { | 169 | + } elseif ($attr == 'manager_id') { |
| 170 | + $users = User::find() | ||
| 171 | + ->indexBy('id') | ||
| 172 | + ->all(); | ||
| 146 | return [ | 173 | return [ |
| 147 | - 'old' => empty($values['old']) ? '' : $labels[$values['old']]->lang->title, | ||
| 148 | - 'new' => empty($values['new']) ? '' : $labels[$values['new']]->lang->title, | 174 | + 'old' => empty($values[ 'old' ]) ? '' : $users[ $values[ 'old' ] ]->username, |
| 175 | + 'new' => empty($values[ 'new' ]) ? '' : $users[ $values[ 'new' ] ]->username, | ||
| 149 | ]; | 176 | ]; |
| 177 | + } elseif ($attr == 'payment') { | ||
| 178 | + $payment = OrderPayment::find() | ||
| 179 | + ->with('lang') | ||
| 180 | + ->indexBy('id') | ||
| 181 | + ->all(); | ||
| 182 | + return [ | ||
| 183 | + 'old' => empty($values[ 'old' ]) ? '' : $payment[ $values[ 'old' ] ]->lang->title, | ||
| 184 | + 'new' => empty($values[ 'new' ]) ? '' : $payment[ $values[ 'new' ] ]->lang->title, | ||
| 185 | + ]; | ||
| 186 | + } elseif ($attr == 'shipping_by') { | ||
| 187 | + return [ | ||
| 188 | + 'old' => empty($values[ 'old' ]) ? '' : self::SHIPPING_BY[ $values[ 'old' ] ][ 'label' ], | ||
| 189 | + 'new' => empty($values[ 'new' ]) ? '' : self::SHIPPING_BY[ $values[ 'new' ] ][ 'label' ], | ||
| 190 | + ]; | ||
| 191 | + } elseif ($attr == 'pay') { | ||
| 192 | + return [ | ||
| 193 | + 'old' => ($values[ 'old' ] == true) ? 'Оплачен' : 'Не оплачен', | ||
| 194 | + 'new' => ($values[ 'new' ] == true) ? 'Оплачен' : 'Не оплачен', | ||
| 195 | + ]; | ||
| 196 | + } else { | ||
| 197 | + return $values; | ||
| 150 | } | 198 | } |
| 151 | } | 199 | } |
| 152 | 200 | ||
| @@ -263,13 +311,17 @@ | @@ -263,13 +311,17 @@ | ||
| 263 | 311 | ||
| 264 | public function afterSave($insert, $changedAttributes) | 312 | public function afterSave($insert, $changedAttributes) |
| 265 | { | 313 | { |
| 314 | +// VarDumper::dump($changedAttributes, 10, true);die(); | ||
| 266 | $data = []; | 315 | $data = []; |
| 267 | foreach ($changedAttributes as $key => $attribute) { | 316 | foreach ($changedAttributes as $key => $attribute) { |
| 268 | if ($this->oldAttributes[ $key ] != $attribute) { | 317 | if ($this->oldAttributes[ $key ] != $attribute) { |
| 269 | - $data[ $key ] = [ | ||
| 270 | - 'old' => $attribute, | ||
| 271 | - 'new' => $this->oldAttributes[ $key ], | ||
| 272 | - ]; | 318 | + $data[ $key ] = $this->getLogAttributes( |
| 319 | + $key, | ||
| 320 | + [ | ||
| 321 | + 'old' => $attribute, | ||
| 322 | + 'new' => $this->oldAttributes[ $key ], | ||
| 323 | + ] | ||
| 324 | + ); | ||
| 273 | } | 325 | } |
| 274 | } | 326 | } |
| 275 | 327 |
views/order/_log_item.php
| @@ -12,18 +12,18 @@ | @@ -12,18 +12,18 @@ | ||
| 12 | <!-- timeline item --> | 12 | <!-- timeline item --> |
| 13 | <li> | 13 | <li> |
| 14 | <!-- timeline icon --> | 14 | <!-- timeline icon --> |
| 15 | - <i class="fa fa-tag bg-blue"></i> | 15 | + <i class="fa fa-user bg-orange"></i> |
| 16 | <div class="timeline-item"> | 16 | <div class="timeline-item"> |
| 17 | <span class="time"><i class="fa fa-calendar"></i> <?= Yii::$app->formatter->asDatetime($model->created_at) ?></span> | 17 | <span class="time"><i class="fa fa-calendar"></i> <?= Yii::$app->formatter->asDatetime($model->created_at) ?></span> |
| 18 | 18 | ||
| 19 | - <h3 class="timeline-header">Title</h3> | 19 | + <h3 class="timeline-header">Пользователь: <span class="text-orange"><?=$model->user->username?></span></h3> |
| 20 | 20 | ||
| 21 | <div class="timeline-body"> | 21 | <div class="timeline-body"> |
| 22 | - <table class="table table-bordered"> | 22 | + <table class="table table-bordered table-striped"> |
| 23 | <tr> | 23 | <tr> |
| 24 | <th>Поле</th> | 24 | <th>Поле</th> |
| 25 | - <th>с</th> | ||
| 26 | - <th>на</th> | 25 | + <th>Старое значение</th> |
| 26 | + <th>Новое значение</th> | ||
| 27 | </tr> | 27 | </tr> |
| 28 | <?php | 28 | <?php |
| 29 | foreach (Json::decode($model->data) as $key => $item) { | 29 | foreach (Json::decode($model->data) as $key => $item) { |
views/order/index.php
| @@ -347,7 +347,7 @@ JS; | @@ -347,7 +347,7 @@ JS; | ||
| 347 | [ | 347 | [ |
| 348 | 'class' => 'yii\grid\ActionColumn', | 348 | 'class' => 'yii\grid\ActionColumn', |
| 349 | 'template' => \Yii::$app->user->identity->isAdmin( | 349 | 'template' => \Yii::$app->user->identity->isAdmin( |
| 350 | - ) ? '{view} {update} {delete}' : '{view} {update}', | 350 | + ) ? '{history} {view} {update} {delete}' : '{view} {update}', |
| 351 | 'buttons' => [ | 351 | 'buttons' => [ |
| 352 | 'update' => function($url, $model) { | 352 | 'update' => function($url, $model) { |
| 353 | return Html::a( | 353 | return Html::a( |
| @@ -359,6 +359,16 @@ JS; | @@ -359,6 +359,16 @@ JS; | ||
| 359 | ] | 359 | ] |
| 360 | ); | 360 | ); |
| 361 | }, | 361 | }, |
| 362 | + 'history' => function($url, $model) { | ||
| 363 | + return Html::a( | ||
| 364 | + Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-time' ]), | ||
| 365 | + ['log', 'id' => $model->id], | ||
| 366 | + [ | ||
| 367 | + 'target' => '_blank', | ||
| 368 | + 'data-pjax' => '0', | ||
| 369 | + ] | ||
| 370 | + ); | ||
| 371 | + }, | ||
| 362 | ], | 372 | ], |
| 363 | ], | 373 | ], |
| 364 | ], | 374 | ], |
views/order/log.php
| @@ -9,41 +9,51 @@ | @@ -9,41 +9,51 @@ | ||
| 9 | * @var ActiveDataProvider $logData | 9 | * @var ActiveDataProvider $logData |
| 10 | * @var Order $model | 10 | * @var Order $model |
| 11 | */ | 11 | */ |
| 12 | - | 12 | + |
| 13 | + $this->title = 'История заказа #' . $model->id; | ||
| 14 | + | ||
| 15 | + $this->params[ 'breadcrumbs' ][] = [ | ||
| 16 | + 'url' => yii\helpers\Url::to([ '/ecommerce/order/index' ]), | ||
| 17 | + 'label' => \Yii::t('app', 'Заказы'), | ||
| 18 | + ]; | ||
| 19 | + $this->params[ 'breadcrumbs' ][] = [ | ||
| 20 | + 'url' => yii\helpers\Url::to([ '/ecommerce/order/view', 'id' => $model->id ]), | ||
| 21 | + 'label' => \Yii::t('app', 'Заказ #') . $model->id, | ||
| 22 | + ]; | ||
| 23 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
| 24 | + | ||
| 13 | ?> | 25 | ?> |
| 14 | 26 | ||
| 15 | <div class="order-log"> | 27 | <div class="order-log"> |
| 16 | <div class="box box-default"> | 28 | <div class="box box-default"> |
| 17 | <div class="box-header with-border"> | 29 | <div class="box-header with-border"> |
| 18 | <h3 class="box-title">История</h3> | 30 | <h3 class="box-title">История</h3> |
| 19 | -<!-- <div class="box-tools pull-right">--> | ||
| 20 | -<!-- <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>--> | ||
| 21 | -<!-- </div>--> | ||
| 22 | - </div><!-- /.box-header --> | ||
| 23 | - <div class="box-body"> | 31 | + <div class="box-body"> |
| 24 | 32 | ||
| 33 | + <?php | ||
| 34 | + echo ListView::widget( | ||
| 35 | + [ | ||
| 36 | + 'dataProvider' => $logData, | ||
| 37 | + 'layout' => '{items}', | ||
| 38 | + 'itemView' => '_log_item', | ||
| 39 | + 'itemOptions' => [ | ||
| 40 | + 'tag' => false, | ||
| 41 | + ], | ||
| 42 | + 'options' => [ | ||
| 43 | + 'tag' => $logData->totalCount == 0 ? 'div' : 'ul', | ||
| 44 | + 'class' => $logData->totalCount == 0 ? 'list-view' : 'list-view timeline', | ||
| 45 | + ], | ||
| 46 | + 'viewParams' => [ | ||
| 47 | + 'order' => $model, | ||
| 48 | + ], | ||
| 49 | + 'emptyText' => 'У этого заказа пока нет истории', | ||
| 50 | + 'emptyTextOptions' => [ | ||
| 51 | + 'class' => 'callout callout-info' | ||
| 52 | + ], | ||
| 53 | + ] | ||
| 54 | + ); | ||
| 55 | + ?> | ||
| 25 | 56 | ||
| 26 | - <?php | ||
| 27 | - echo ListView::widget( | ||
| 28 | - [ | ||
| 29 | - 'dataProvider' => $logData, | ||
| 30 | - 'layout' => '{items}', | ||
| 31 | - 'itemView' => '_log_item', | ||
| 32 | - 'itemOptions' => [ | ||
| 33 | - 'tag' => false, | ||
| 34 | - ], | ||
| 35 | - 'options' => [ | ||
| 36 | - 'tag' => 'ul', | ||
| 37 | - 'class' => 'list-view timeline', | ||
| 38 | - ], | ||
| 39 | - 'viewParams' => [ | ||
| 40 | - 'order' => $model, | ||
| 41 | - ], | ||
| 42 | - ] | ||
| 43 | - ); | ||
| 44 | - ?> | ||
| 45 | - | ||
| 46 | - | ||
| 47 | - </div><!-- /.box-body --> | ||
| 48 | - </div><!-- /.box --> | ||
| 49 | -</div> | 57 | + </div><!-- /.box-body --> |
| 58 | + </div><!-- /.box --> | ||
| 59 | + </div> |
views/order/view.php
| @@ -36,7 +36,15 @@ | @@ -36,7 +36,15 @@ | ||
| 36 | ], | 36 | ], |
| 37 | [ 'class' => 'btn btn-primary' ] | 37 | [ 'class' => 'btn btn-primary' ] |
| 38 | ) ?> | 38 | ) ?> |
| 39 | - | 39 | + |
| 40 | + <?= Html::a( | ||
| 41 | + 'История', | ||
| 42 | + [ | ||
| 43 | + 'log', | ||
| 44 | + 'id' => $model->id, | ||
| 45 | + ], | ||
| 46 | + [ 'class' => 'btn bg-orange' ] | ||
| 47 | + ) ?> | ||
| 40 | </p> | 48 | </p> |
| 41 | 49 | ||
| 42 | <div class="box box-default"> | 50 | <div class="box box-default"> |
| @@ -54,7 +62,10 @@ | @@ -54,7 +62,10 @@ | ||
| 54 | 'id', | 62 | 'id', |
| 55 | 'deadline', | 63 | 'deadline', |
| 56 | 'pay', | 64 | 'pay', |
| 57 | - 'reason', | 65 | + [ |
| 66 | + 'label' => 'Причина', | ||
| 67 | + 'value' => empty($model->reason) ? '' : Order::REASONS[$model->reason], | ||
| 68 | + ], | ||
| 58 | [ | 69 | [ |
| 59 | 'label' => 'Статус', | 70 | 'label' => 'Статус', |
| 60 | 'value' => $model->orderLabel->lang->title, | 71 | 'value' => $model->orderLabel->lang->title, |