diff --git a/controllers/OrderController.php b/controllers/OrderController.php index 5b0228b..963e7c7 100755 --- a/controllers/OrderController.php +++ b/controllers/OrderController.php @@ -2,6 +2,7 @@ namespace artweb\artbox\ecommerce\controllers; + use artweb\artbox\components\SmsSender; use artweb\artbox\ecommerce\models\OrderSearch; use phpDocumentor\Reflection\Types\Null_; use Yii; @@ -98,6 +99,21 @@ $model->save(); } + public function actionView($id) + { + $model = $this->findModel($id); + $dataProvider = new ActiveDataProvider([ + 'query' => $model->getProducts(), + ]); + return $this->render( + 'view', + [ + 'model' => $model, + 'products' => $dataProvider, + ] + ); + } + public function actionPayUpdate() { $model = Order::findOne($_POST[ 'order_id' ]); @@ -300,14 +316,13 @@ ], ]; if (!is_null($q)) { - $result = ProductVariant::find() -// ->select( -// [ -// 'id', -// 'sku', -// 'product_lang.title AS name' -// ] -// ) + $result = ProductVariant::find()// ->select( + // [ + // 'id', + // 'sku', + // 'product_lang.title AS name' + // ] + // ) ->joinWith('product.lang') ->where( [ @@ -325,6 +340,15 @@ return $out; } + public function actionSendSms() + { + $phone = \Yii::$app->request->post('phone'); + $content = \Yii::$app->request->post('content'); + $sender = \Yii::$app->sender; + $result = $sender->send($phone, $content); + return $phone . $content . $result; + } + // public function actionDeleteProduct($id, $order_id) // { // $model = OrderProduct::findOne($id); diff --git a/models/Order.php b/models/Order.php index 4cf4380..6b88efd 100755 --- a/models/Order.php +++ b/models/Order.php @@ -61,6 +61,26 @@ ], ]; + const REASONS = [ + 1 => 'Нет товара', + 2 => 'Нет оплаты', + 3 => 'Передумал', + 4 => ' - Купил в другом месте', + 5 => ' - Не подошли условия доставки', + 6 => ' - Не подошел срок доставки', + 7 => ' - Нет денег', + 8 => ' - Купит позже', + 9 => 'Купил в другом месте', + 10 => 'Подьедет в маг.', + 11 => 'Дубль заказа.', + 12 => 'Другое', + 13 => 'Брак', + 14 => 'Отказался от Самовывоза', + 15 => 'Не приехал за Самовывозом', + 16 => 'Отменил заказ', + 17 => 'Не берет трубку', + ]; + public static function tableName() { return 'order'; diff --git a/views/order/_form.php b/views/order/_form.php index 2ee7d5e..1a4f8b7 100755 --- a/views/order/_form.php +++ b/views/order/_form.php @@ -9,7 +9,6 @@ use kartik\widgets\DatePicker; use kartik\widgets\Select2; use kartik\widgets\SwitchInput; - use yii\bootstrap\Dropdown; use yii\data\ActiveDataProvider; use yii\helpers\Html; use yii\bootstrap\ActiveForm; @@ -58,9 +57,31 @@ JS; $js = <<< JS $(document).on('change', '#sms-template-selector', function(event) { var text = $('#select2-sms-template-selector-container').attr('title'); - var val = $('option:contains(' + text + ')') - console.log(text); - console.log(val); + var val = $('option:contains(' + text + ')').attr('value'); + $('#sms-text-area').val(val); +}); + +$(document).on('click', '#send-sms-action', function(event) { + console.log('click'); + var content = $('#sms-text-area').val() + var phone = $('input#order-phone').val(); + $.ajax({ + url: "/admin/ecommerce/order/send-sms", + method: "POST", + data: { + phone: phone, + content: content + }, + success: function(data) { + console.log(data); + var newButton = document.createElement('button'); + newButton.classList.add('btn', 'btn-default'); + newButton.innerText = 'Отправлено'; + var current = document.getElementById("send-sms-action"); + var parentDiv = current.parentNode; + parentDiv.replaceChild(newButton, current); + } + }); }); JS; @@ -72,8 +93,8 @@ JS;
isNewRecord ? \Yii::t('app', 'Create') : \Yii::t('app', 'Update'), - [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] + $model->isNewRecord ? \Yii::t('app', 'Создать') : \Yii::t('app', 'Обновить'), + [ 'class' => $model->isNewRecord ? 'btn btn-success btn-lg' : 'btn btn-primary btn-lg' ] ) ?> $model->isNewRecord ? 'btn btn-info disabled' : 'btn btn-info', + 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', 'target' => '_blank', ] ) ?>
+
@@ -115,10 +137,7 @@ JS; field($model, 'reason') ->dropDownList( - [ - 1 => 'То', - 2 => 'Сё', - ], + Order::REASONS, [ 'prompt' => 'Выберите причину' ] ) ?> @@ -263,9 +282,6 @@ JS; 'max' => 20, ], ], - 'pluginEvents' => [ - 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', - ], ], 'format' => [ 'text', @@ -284,37 +300,25 @@ JS; 'max' => 20, ], ], - 'pluginEvents' => [ - 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', - ], ], 'format' => [ 'text', ], 'pageSummary' => false, ], -// [ -// 'class' => 'kartik\grid\EditableColumn', -// 'attribute' => 'count', -// 'editableOptions' => [ -// 'header' => \Yii::t('app', 'Количество'), -// 'inputType' => kartik\editable\Editable::INPUT_SPIN, -// 'options' => [ -// 'pluginOptions' => [ -// 'min' => 0, -// 'max' => 5000, -// ], -// ], -// 'pluginEvents' => [ -// 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', -// ], -// ], -// 'format' => [ -// 'decimal', -// 0, -// ], -// 'pageSummary' => false, -// ], + [ + 'class' => 'kartik\grid\EditableColumn', + 'attribute' => 'return', + 'editableOptions' => [ + 'header' => \Yii::t('app', 'Возврат'), + 'inputType' => kartik\editable\Editable::INPUT_CHECKBOX, + 'options' => [], + ], + 'format' => [ + 'boolean', + ], + 'pageSummary' => false, + ], [ 'class' => 'yii\grid\ActionColumn', 'template' => '{delete}', @@ -383,10 +387,18 @@ JS; ?>
- field($newOrderProduct, 'count') - ->input('number'); ?> + field( + $newOrderProduct, + 'count' + ) + ->input( + 'number', + [ + 'disabled' => $model->isNewRecord ? true : false, + ] + ); ?>
-
+


-
-
-
+

'sms-template-selector', + 'id' => 'sms-template-selector', 'name' => 'select-sms-template', 'data' => ArrayHelper::map( SmsTemplate::find() @@ -431,15 +441,36 @@ JS; ); ?> - +
5, + 'rows' => 3, + 'id' => 'sms-text-area', + 'class' => 'form-control', ] ); ?> +
+ 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', + ] + ); + } + ?>
diff --git a/views/order/create.php b/views/order/create.php index 3866140..aa61dd6 100755 --- a/views/order/create.php +++ b/views/order/create.php @@ -11,14 +11,16 @@ $this->title = 'Добавить товар в заказ'; $this->params[ 'breadcrumbs' ][] = [ - 'label' => 'Pages', + 'label' => \Yii::t('app', 'Заказы'), 'url' => [ 'index' ], ]; $this->params[ 'breadcrumbs' ][] = $this->title; ?>
-

title) ?>

+
+

title) ?>

+
render( '_form', diff --git a/views/order/index.php b/views/order/index.php index 308e870..7095c8c 100755 --- a/views/order/index.php +++ b/views/order/index.php @@ -33,7 +33,7 @@ $('[name="OrderSearch[phone]"]').mask('+38(000)000-00-00', { JS; $this->registerJs($js, View::POS_READY); - + ?>

Заказы

@@ -107,9 +107,9 @@ JS; ?> field($searchModel, 'sku') ->widget( Select2::className(), diff --git a/views/order/update.php b/views/order/update.php index 6f5f4cf..701703e 100755 --- a/views/order/update.php +++ b/views/order/update.php @@ -11,10 +11,14 @@ use yii\web\View; $this->title = 'Заказ #' . $model->id; + $this->params[ 'breadcrumbs' ][] = [ + 'url' => yii\helpers\Url::to([ '/ecommerce/order/index' ]), + 'label' => \Yii::t('app', 'Заказы'), + ]; $this->params[ 'breadcrumbs' ][] = $this->title; ?>

-

title) ?>

+

title) ?>

render( '_form', diff --git a/views/order/view.php b/views/order/view.php new file mode 100755 index 0000000..e0e3deb --- /dev/null +++ b/views/order/view.php @@ -0,0 +1,81 @@ +title = 'Заказ #' . $model->id; + $this->params[ 'breadcrumbs' ][] = [ + 'label' => \Yii::t('app', 'Заказы'), + 'url' => [ 'index' ], + ]; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +
+ +

title) ?>

+ +

+ $model->id, + ], + [ 'class' => 'btn btn-primary' ] + ) ?> + +

+ + $model, + 'attributes' => [ + 'id', + 'deadline', + 'pay', + 'reason', + 'label', + 'name', + 'phone', + 'email', + 'comment', + 'delivery', + 'declaration', + 'stock', + 'payment', + 'insurance', + 'city', + 'adress', + 'body', + 'check', + 'sms', + ], + ] + ) ?> + + $products, + 'columns' => [ + 'id', + 'product_name', + 'name', + 'sku', + 'price', + 'count', + 'sum_cost', + ], + ] + ); + ?> + +
-- libgit2 0.21.4