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;
@@ -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; ?>
+ = Html::a( + 'Update', + [ + 'update', + 'id' => $model->id, + ], + [ 'class' => 'btn btn-primary' ] + ) ?> + +
+ + = DetailView::widget( + [ + 'model' => $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', + ], + ] + ); + ?> + +