diff --git a/controllers/OrderController.php b/controllers/OrderController.php index 2413aa1..1f505b5 100755 --- a/controllers/OrderController.php +++ b/controllers/OrderController.php @@ -229,6 +229,9 @@ } $model = new Order(); + $model->phone = '+38(000)000-00-00'; + $model->name = \Yii::t('app', 'Новый заказ'); + $model->save(); $dataProvider = new ActiveDataProvider( [ @@ -324,7 +327,13 @@ if ($model->load(Yii::$app->request->post()) && $model->save()) { $this->unblockOrder($model->id); - return $this->redirect([ 'index' ]); + return $this->render( + 'update', + [ + 'model' => $model, + 'dataProvider' => $dataProvider, + ] + ); } else { return $this->render( 'update', @@ -401,7 +410,10 @@ public function actionExitOrder($id) { - $this->unblockOrder($id); + $model = $this->findModel($id); + if ($model->edit_id == \Yii::$app->user->id) { + $this->unblockOrder($id); + } return $this->redirect('index'); } @@ -412,6 +424,9 @@ $model = $this->findModel(\Yii::$app->request->post('id')); + $user = User::find() + ->where([ 'id' => $model->edit_id ]) + ->one(); $model->edit_time = time(); $model->edit_id = \Yii::$app->user->id; @@ -421,6 +436,7 @@ if ($model->save()) { return [ 'time' => $date, + 'user' => !empty( $user ) ? $user->username : '', ]; } else { return [ diff --git a/models/Order.php b/models/Order.php index 092d2ee..5c19845 100755 --- a/models/Order.php +++ b/models/Order.php @@ -293,7 +293,7 @@ */ public function getManager() { - $this->hasOne(User::className(), [ 'id' => 'manager_id' ]); + return $this->hasOne(User::className(), [ 'id' => 'manager_id' ]); } public function isBlocked() diff --git a/models/OrderSearch.php b/models/OrderSearch.php index 1fe71cb..e353033 100755 --- a/models/OrderSearch.php +++ b/models/OrderSearch.php @@ -75,6 +75,7 @@ $dataProvider = new ActiveDataProvider( [ 'query' => $query, + 'sort' => [ 'defaultOrder' => [ 'id' => SORT_DESC ] ], ] ); @@ -155,7 +156,7 @@ $query->andFilterWhere( [ 'manager_id' => $this->manager_id, - + ] ); $query->andFilterWhere( diff --git a/views/order/_form.php b/views/order/_form.php index d979de6..ae188c3 100755 --- a/views/order/_form.php +++ b/views/order/_form.php @@ -63,9 +63,14 @@ $(document).on('change', '#sms-template-selector', function(event) { }); $(document).on('click', '#send-sms-action', function(event) { - console.log('click'); - var content = $('#sms-text-area').val() - var phone = $('input#order-phone').val(); + var variant = $('input[name=send-phone]:checked').val(); + var content = $('#sms-text-area').val(); + if (variant == 1) { + var phone = $('input#order-phone').val(); + } else if (variant == 2) { + var phone = $('input#order-phone2').val(); + } + console.log(phone); $.ajax({ url: "/admin/ecommerce/order/send-sms", method: "POST", @@ -87,9 +92,18 @@ $(document).on('click', '#send-sms-action', function(event) { JS; $this->registerJs($js, View::POS_READY); + + $js = <<< JS +$(document).on('click', '#page-submit', function() { + $('#main-form').trigger('submit'); +}); +JS; + + $this->registerJs($js, View::POS_READY); + ?> - + 'main-form' ]); ?>

@@ -215,24 +229,40 @@ JS; ); ?>
- isNewRecord) { - echo Html::button( - \Yii::t('app', 'Отправить'), - [ - 'class' => 'btn btn-warning disabled', - ] - ); - } else { - echo Html::button( - \Yii::t('app', 'Отправить'), - [ - 'class' => 'btn btn-warning', - 'id' => 'send-sms-action', - ] - ); - } - ?> +
+
+ isNewRecord) { + echo Html::button( + \Yii::t('app', 'Отправить'), + [ + 'class' => 'btn btn-warning disabled', + ] + ); + } else { + echo Html::button( + \Yii::t('app', 'Отправить'), + [ + 'class' => 'btn btn-warning', + 'id' => 'send-sms-action', + ] + ); + } + ?> +
+
+ 'Первый номер', + '2' => 'Второй номер', + ] + ); + ?> +
+
@@ -280,38 +310,6 @@ JS;
-
-
- isNewRecord ? \Yii::t('app', 'Создать') : \Yii::t('app', 'Обновить'), - [ 'class' => $model->isNewRecord ? 'btn btn-success btn-lg' : 'btn btn-primary btn-lg' ] - ) ?> - $model->id, - ] - ), - [ - 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', - 'target' => '_blank', - ] - ) ?> - $model->id, - ] - ), - [ - 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', - ] - ) ?> -
@@ -377,8 +375,12 @@ JS; 'attribute' => 'status', 'editableOptions' => [ 'header' => \Yii::t('app', 'Статус'), - 'inputType' => kartik\editable\Editable::INPUT_TEXT, + 'inputType' => kartik\editable\Editable::INPUT_SELECT2, 'options' => [ + 'data' => [ + 0 => 'adsas', + 2 => 'dSSSSasda', + ], 'pluginOptions' => [ 'min' => 0, 'max' => 20, @@ -516,6 +518,43 @@ JS; ->label(false) ?> + +
+
+ isNewRecord ? \Yii::t('app', 'Создать') : \Yii::t('app', 'Сохранить'), + [ + 'class' => $model->isNewRecord ? 'btn btn-success btn-lg' : 'btn btn-primary btn-lg', + 'id' => 'page-submit', + ] + ) ?> + $model->id, + ] + ), + [ + 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', + 'target' => '_blank', + ] + ) ?> + $model->id, + ] + ), + [ + 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', + ] + ) ?> +
+

diff --git a/views/order/index.php b/views/order/index.php index 443a2d3..ea8467b 100755 --- a/views/order/index.php +++ b/views/order/index.php @@ -189,6 +189,14 @@ JS; 'attribute' => 'id', 'filter' => $searchForm->field($searchModel, 'id') ->textInput(), + 'content' => function($model) { + $manager = $model->manager; + if (empty($manager)) { + return $model->id; + } else { + return $model->id . ' ' . $manager->username; + } + } ], [ 'attribute' => 'created_at', diff --git a/views/order/update.php b/views/order/update.php index 9cbf771..80cf321 100755 --- a/views/order/update.php +++ b/views/order/update.php @@ -25,8 +25,12 @@ $.ajax({ id: ' . $model->id . ' }, success: function(data) { + var message = data.time; + if (data.user != "") { + message += " " + data.user; + } $.notify({ - message: data.time + message: message },{ type: "info" }); @@ -35,6 +39,23 @@ $.ajax({ $this->registerJs($js, View::POS_READY); + $js = ' + window.onbeforeunload = function(e) { + $.ajax({ + type: "GET", + url: "/admin/ecommerce/order/exit-order", + data: { + id: ' . $model->id . ', + }, + success: function() { + console.log("Exit order"); + } + }); +}; +'; + + $this->registerJs($js, View::POS_READY); + ?>

title) ?>

-- libgit2 0.21.4