Commit db3040d3c9ec9a3c6a7364f8ea6bad043835739f
1 parent
0893579c
-Order module almost ready (need to add roles)
Showing
7 changed files
with
225 additions
and
63 deletions
Show diff stats
controllers/OrderController.php
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\controllers; | 3 | namespace artweb\artbox\ecommerce\controllers; |
4 | 4 | ||
5 | + use artweb\artbox\components\SmsSender; | ||
5 | use artweb\artbox\ecommerce\models\OrderSearch; | 6 | use artweb\artbox\ecommerce\models\OrderSearch; |
6 | use phpDocumentor\Reflection\Types\Null_; | 7 | use phpDocumentor\Reflection\Types\Null_; |
7 | use Yii; | 8 | use Yii; |
@@ -98,6 +99,21 @@ | @@ -98,6 +99,21 @@ | ||
98 | $model->save(); | 99 | $model->save(); |
99 | } | 100 | } |
100 | 101 | ||
102 | + public function actionView($id) | ||
103 | + { | ||
104 | + $model = $this->findModel($id); | ||
105 | + $dataProvider = new ActiveDataProvider([ | ||
106 | + 'query' => $model->getProducts(), | ||
107 | + ]); | ||
108 | + return $this->render( | ||
109 | + 'view', | ||
110 | + [ | ||
111 | + 'model' => $model, | ||
112 | + 'products' => $dataProvider, | ||
113 | + ] | ||
114 | + ); | ||
115 | + } | ||
116 | + | ||
101 | public function actionPayUpdate() | 117 | public function actionPayUpdate() |
102 | { | 118 | { |
103 | $model = Order::findOne($_POST[ 'order_id' ]); | 119 | $model = Order::findOne($_POST[ 'order_id' ]); |
@@ -300,14 +316,13 @@ | @@ -300,14 +316,13 @@ | ||
300 | ], | 316 | ], |
301 | ]; | 317 | ]; |
302 | if (!is_null($q)) { | 318 | if (!is_null($q)) { |
303 | - $result = ProductVariant::find() | ||
304 | -// ->select( | ||
305 | -// [ | ||
306 | -// 'id', | ||
307 | -// 'sku', | ||
308 | -// 'product_lang.title AS name' | ||
309 | -// ] | ||
310 | -// ) | 319 | + $result = ProductVariant::find()// ->select( |
320 | + // [ | ||
321 | + // 'id', | ||
322 | + // 'sku', | ||
323 | + // 'product_lang.title AS name' | ||
324 | + // ] | ||
325 | + // ) | ||
311 | ->joinWith('product.lang') | 326 | ->joinWith('product.lang') |
312 | ->where( | 327 | ->where( |
313 | [ | 328 | [ |
@@ -325,6 +340,15 @@ | @@ -325,6 +340,15 @@ | ||
325 | return $out; | 340 | return $out; |
326 | } | 341 | } |
327 | 342 | ||
343 | + public function actionSendSms() | ||
344 | + { | ||
345 | + $phone = \Yii::$app->request->post('phone'); | ||
346 | + $content = \Yii::$app->request->post('content'); | ||
347 | + $sender = \Yii::$app->sender; | ||
348 | + $result = $sender->send($phone, $content); | ||
349 | + return $phone . $content . $result; | ||
350 | + } | ||
351 | + | ||
328 | // public function actionDeleteProduct($id, $order_id) | 352 | // public function actionDeleteProduct($id, $order_id) |
329 | // { | 353 | // { |
330 | // $model = OrderProduct::findOne($id); | 354 | // $model = OrderProduct::findOne($id); |
models/Order.php
@@ -61,6 +61,26 @@ | @@ -61,6 +61,26 @@ | ||
61 | ], | 61 | ], |
62 | ]; | 62 | ]; |
63 | 63 | ||
64 | + const REASONS = [ | ||
65 | + 1 => 'Нет товара', | ||
66 | + 2 => 'Нет оплаты', | ||
67 | + 3 => 'Передумал', | ||
68 | + 4 => ' - Купил в другом месте', | ||
69 | + 5 => ' - Не подошли условия доставки', | ||
70 | + 6 => ' - Не подошел срок доставки', | ||
71 | + 7 => ' - Нет денег', | ||
72 | + 8 => ' - Купит позже', | ||
73 | + 9 => 'Купил в другом месте', | ||
74 | + 10 => 'Подьедет в маг.', | ||
75 | + 11 => 'Дубль заказа.', | ||
76 | + 12 => 'Другое', | ||
77 | + 13 => 'Брак', | ||
78 | + 14 => 'Отказался от Самовывоза', | ||
79 | + 15 => 'Не приехал за Самовывозом', | ||
80 | + 16 => 'Отменил заказ', | ||
81 | + 17 => 'Не берет трубку', | ||
82 | + ]; | ||
83 | + | ||
64 | public static function tableName() | 84 | public static function tableName() |
65 | { | 85 | { |
66 | return 'order'; | 86 | return 'order'; |
views/order/_form.php
@@ -9,7 +9,6 @@ | @@ -9,7 +9,6 @@ | ||
9 | use kartik\widgets\DatePicker; | 9 | use kartik\widgets\DatePicker; |
10 | use kartik\widgets\Select2; | 10 | use kartik\widgets\Select2; |
11 | use kartik\widgets\SwitchInput; | 11 | use kartik\widgets\SwitchInput; |
12 | - use yii\bootstrap\Dropdown; | ||
13 | use yii\data\ActiveDataProvider; | 12 | use yii\data\ActiveDataProvider; |
14 | use yii\helpers\Html; | 13 | use yii\helpers\Html; |
15 | use yii\bootstrap\ActiveForm; | 14 | use yii\bootstrap\ActiveForm; |
@@ -58,9 +57,31 @@ JS; | @@ -58,9 +57,31 @@ JS; | ||
58 | $js = <<< JS | 57 | $js = <<< JS |
59 | $(document).on('change', '#sms-template-selector', function(event) { | 58 | $(document).on('change', '#sms-template-selector', function(event) { |
60 | var text = $('#select2-sms-template-selector-container').attr('title'); | 59 | var text = $('#select2-sms-template-selector-container').attr('title'); |
61 | - var val = $('option:contains(' + text + ')') | ||
62 | - console.log(text); | ||
63 | - console.log(val); | 60 | + var val = $('option:contains(' + text + ')').attr('value'); |
61 | + $('#sms-text-area').val(val); | ||
62 | +}); | ||
63 | + | ||
64 | +$(document).on('click', '#send-sms-action', function(event) { | ||
65 | + console.log('click'); | ||
66 | + var content = $('#sms-text-area').val() | ||
67 | + var phone = $('input#order-phone').val(); | ||
68 | + $.ajax({ | ||
69 | + url: "/admin/ecommerce/order/send-sms", | ||
70 | + method: "POST", | ||
71 | + data: { | ||
72 | + phone: phone, | ||
73 | + content: content | ||
74 | + }, | ||
75 | + success: function(data) { | ||
76 | + console.log(data); | ||
77 | + var newButton = document.createElement('button'); | ||
78 | + newButton.classList.add('btn', 'btn-default'); | ||
79 | + newButton.innerText = 'Отправлено'; | ||
80 | + var current = document.getElementById("send-sms-action"); | ||
81 | + var parentDiv = current.parentNode; | ||
82 | + parentDiv.replaceChild(newButton, current); | ||
83 | + } | ||
84 | + }); | ||
64 | }); | 85 | }); |
65 | JS; | 86 | JS; |
66 | 87 | ||
@@ -72,8 +93,8 @@ JS; | @@ -72,8 +93,8 @@ JS; | ||
72 | <div class="form-group"> | 93 | <div class="form-group"> |
73 | <div class="row"> | 94 | <div class="row"> |
74 | <?= Html::submitButton( | 95 | <?= Html::submitButton( |
75 | - $model->isNewRecord ? \Yii::t('app', 'Create') : \Yii::t('app', 'Update'), | ||
76 | - [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | 96 | + $model->isNewRecord ? \Yii::t('app', 'Создать') : \Yii::t('app', 'Обновить'), |
97 | + [ 'class' => $model->isNewRecord ? 'btn btn-success btn-lg' : 'btn btn-primary btn-lg' ] | ||
77 | ) ?> | 98 | ) ?> |
78 | <?= Html::a( | 99 | <?= Html::a( |
79 | \Yii::t('app', 'Печать'), | 100 | \Yii::t('app', 'Печать'), |
@@ -84,11 +105,12 @@ JS; | @@ -84,11 +105,12 @@ JS; | ||
84 | ] | 105 | ] |
85 | ), | 106 | ), |
86 | [ | 107 | [ |
87 | - 'class' => $model->isNewRecord ? 'btn btn-info disabled' : 'btn btn-info', | 108 | + 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', |
88 | 'target' => '_blank', | 109 | 'target' => '_blank', |
89 | ] | 110 | ] |
90 | ) ?> | 111 | ) ?> |
91 | </div> | 112 | </div> |
113 | + <br> | ||
92 | <div class="row"> | 114 | <div class="row"> |
93 | <div class="col-sm-6"> | 115 | <div class="col-sm-6"> |
94 | 116 | ||
@@ -115,10 +137,7 @@ JS; | @@ -115,10 +137,7 @@ JS; | ||
115 | 137 | ||
116 | <?= $form->field($model, 'reason') | 138 | <?= $form->field($model, 'reason') |
117 | ->dropDownList( | 139 | ->dropDownList( |
118 | - [ | ||
119 | - 1 => 'То', | ||
120 | - 2 => 'Сё', | ||
121 | - ], | 140 | + Order::REASONS, |
122 | [ 'prompt' => 'Выберите причину' ] | 141 | [ 'prompt' => 'Выберите причину' ] |
123 | ) ?> | 142 | ) ?> |
124 | 143 | ||
@@ -263,9 +282,6 @@ JS; | @@ -263,9 +282,6 @@ JS; | ||
263 | 'max' => 20, | 282 | 'max' => 20, |
264 | ], | 283 | ], |
265 | ], | 284 | ], |
266 | - 'pluginEvents' => [ | ||
267 | - 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', | ||
268 | - ], | ||
269 | ], | 285 | ], |
270 | 'format' => [ | 286 | 'format' => [ |
271 | 'text', | 287 | 'text', |
@@ -284,37 +300,25 @@ JS; | @@ -284,37 +300,25 @@ JS; | ||
284 | 'max' => 20, | 300 | 'max' => 20, |
285 | ], | 301 | ], |
286 | ], | 302 | ], |
287 | - 'pluginEvents' => [ | ||
288 | - 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', | ||
289 | - ], | ||
290 | ], | 303 | ], |
291 | 'format' => [ | 304 | 'format' => [ |
292 | 'text', | 305 | 'text', |
293 | ], | 306 | ], |
294 | 'pageSummary' => false, | 307 | 'pageSummary' => false, |
295 | ], | 308 | ], |
296 | -// [ | ||
297 | -// 'class' => 'kartik\grid\EditableColumn', | ||
298 | -// 'attribute' => 'count', | ||
299 | -// 'editableOptions' => [ | ||
300 | -// 'header' => \Yii::t('app', 'Количество'), | ||
301 | -// 'inputType' => kartik\editable\Editable::INPUT_SPIN, | ||
302 | -// 'options' => [ | ||
303 | -// 'pluginOptions' => [ | ||
304 | -// 'min' => 0, | ||
305 | -// 'max' => 5000, | ||
306 | -// ], | ||
307 | -// ], | ||
308 | -// 'pluginEvents' => [ | ||
309 | -// 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', | ||
310 | -// ], | ||
311 | -// ], | ||
312 | -// 'format' => [ | ||
313 | -// 'decimal', | ||
314 | -// 0, | ||
315 | -// ], | ||
316 | -// 'pageSummary' => false, | ||
317 | -// ], | 309 | + [ |
310 | + 'class' => 'kartik\grid\EditableColumn', | ||
311 | + 'attribute' => 'return', | ||
312 | + 'editableOptions' => [ | ||
313 | + 'header' => \Yii::t('app', 'Возврат'), | ||
314 | + 'inputType' => kartik\editable\Editable::INPUT_CHECKBOX, | ||
315 | + 'options' => [], | ||
316 | + ], | ||
317 | + 'format' => [ | ||
318 | + 'boolean', | ||
319 | + ], | ||
320 | + 'pageSummary' => false, | ||
321 | + ], | ||
318 | [ | 322 | [ |
319 | 'class' => 'yii\grid\ActionColumn', | 323 | 'class' => 'yii\grid\ActionColumn', |
320 | 'template' => '{delete}', | 324 | 'template' => '{delete}', |
@@ -383,10 +387,18 @@ JS; | @@ -383,10 +387,18 @@ JS; | ||
383 | ?> | 387 | ?> |
384 | </div> | 388 | </div> |
385 | <div class="col-md-2"> | 389 | <div class="col-md-2"> |
386 | - <?php echo $newProductForm->field($newOrderProduct, 'count') | ||
387 | - ->input('number'); ?> | 390 | + <?php echo $newProductForm->field( |
391 | + $newOrderProduct, | ||
392 | + 'count' | ||
393 | + ) | ||
394 | + ->input( | ||
395 | + 'number', | ||
396 | + [ | ||
397 | + 'disabled' => $model->isNewRecord ? true : false, | ||
398 | + ] | ||
399 | + ); ?> | ||
388 | </div> | 400 | </div> |
389 | - <div class="col-md-2"> | 401 | + <div class="col-md-2" style="margin-top: 23px"> |
390 | <?php echo Html::submitButton( | 402 | <?php echo Html::submitButton( |
391 | 'Add', | 403 | 'Add', |
392 | [ | 404 | [ |
@@ -406,15 +418,13 @@ JS; | @@ -406,15 +418,13 @@ JS; | ||
406 | </div> | 418 | </div> |
407 | <br> | 419 | <br> |
408 | <br> | 420 | <br> |
409 | -<br> | ||
410 | -<br> | ||
411 | -<br> | ||
412 | <div class="container"> | 421 | <div class="container"> |
422 | + <h2><?php echo \Yii::t('app', 'Отправить смс'); ?></h2> | ||
413 | <div class="row"> | 423 | <div class="row"> |
414 | <?php | 424 | <?php |
415 | echo Select2::widget( | 425 | echo Select2::widget( |
416 | [ | 426 | [ |
417 | - 'id' => 'sms-template-selector', | 427 | + 'id' => 'sms-template-selector', |
418 | 'name' => 'select-sms-template', | 428 | 'name' => 'select-sms-template', |
419 | 'data' => ArrayHelper::map( | 429 | 'data' => ArrayHelper::map( |
420 | SmsTemplate::find() | 430 | SmsTemplate::find() |
@@ -431,15 +441,36 @@ JS; | @@ -431,15 +441,36 @@ JS; | ||
431 | ); | 441 | ); |
432 | 442 | ||
433 | ?> | 443 | ?> |
434 | - | 444 | + <br> |
435 | <?php | 445 | <?php |
436 | echo Html::textarea( | 446 | echo Html::textarea( |
437 | 'sms-text', | 447 | 'sms-text', |
438 | '', | 448 | '', |
439 | [ | 449 | [ |
440 | - 'rows' => 5, | 450 | + 'rows' => 3, |
451 | + 'id' => 'sms-text-area', | ||
452 | + 'class' => 'form-control', | ||
441 | ] | 453 | ] |
442 | ); | 454 | ); |
443 | ?> | 455 | ?> |
456 | + <br> | ||
457 | + <?php | ||
458 | + if ($model->isNewRecord) { | ||
459 | + echo Html::button( | ||
460 | + \Yii::t('app', 'Отправить'), | ||
461 | + [ | ||
462 | + 'class' => 'btn btn-warning disabled', | ||
463 | + ] | ||
464 | + ); | ||
465 | + } else { | ||
466 | + echo Html::button( | ||
467 | + \Yii::t('app', 'Отправить'), | ||
468 | + [ | ||
469 | + 'class' => 'btn btn-warning', | ||
470 | + 'id' => 'send-sms-action', | ||
471 | + ] | ||
472 | + ); | ||
473 | + } | ||
474 | + ?> | ||
444 | </div> | 475 | </div> |
445 | </div> | 476 | </div> |
views/order/create.php
@@ -11,14 +11,16 @@ | @@ -11,14 +11,16 @@ | ||
11 | 11 | ||
12 | $this->title = 'Добавить товар в заказ'; | 12 | $this->title = 'Добавить товар в заказ'; |
13 | $this->params[ 'breadcrumbs' ][] = [ | 13 | $this->params[ 'breadcrumbs' ][] = [ |
14 | - 'label' => 'Pages', | 14 | + 'label' => \Yii::t('app', 'Заказы'), |
15 | 'url' => [ 'index' ], | 15 | 'url' => [ 'index' ], |
16 | ]; | 16 | ]; |
17 | $this->params[ 'breadcrumbs' ][] = $this->title; | 17 | $this->params[ 'breadcrumbs' ][] = $this->title; |
18 | ?> | 18 | ?> |
19 | 19 | ||
20 | <div class="order-create"> | 20 | <div class="order-create"> |
21 | - <h1><?= Html::encode($this->title) ?></h1> | 21 | + <div class="container"> |
22 | + <h1><?= Html::encode($this->title) ?></h1> | ||
23 | + </div> | ||
22 | 24 | ||
23 | <?= $this->render( | 25 | <?= $this->render( |
24 | '_form', | 26 | '_form', |
views/order/index.php
@@ -33,7 +33,7 @@ $('[name="OrderSearch[phone]"]').mask('+38(000)000-00-00', { | @@ -33,7 +33,7 @@ $('[name="OrderSearch[phone]"]').mask('+38(000)000-00-00', { | ||
33 | JS; | 33 | JS; |
34 | 34 | ||
35 | $this->registerJs($js, View::POS_READY); | 35 | $this->registerJs($js, View::POS_READY); |
36 | - | 36 | + |
37 | ?> | 37 | ?> |
38 | <h1>Заказы</h1> | 38 | <h1>Заказы</h1> |
39 | <p> | 39 | <p> |
@@ -107,9 +107,9 @@ JS; | @@ -107,9 +107,9 @@ JS; | ||
107 | ?> | 107 | ?> |
108 | 108 | ||
109 | <?php | 109 | <?php |
110 | - $query = new JsExpression( | ||
111 | - 'function(params) { return {q:params.term}; }' | ||
112 | - ); | 110 | + $query = new JsExpression( |
111 | + 'function(params) { return {q:params.term}; }' | ||
112 | + ); | ||
113 | echo $searchForm->field($searchModel, 'sku') | 113 | echo $searchForm->field($searchModel, 'sku') |
114 | ->widget( | 114 | ->widget( |
115 | Select2::className(), | 115 | Select2::className(), |
views/order/update.php
@@ -11,10 +11,14 @@ | @@ -11,10 +11,14 @@ | ||
11 | use yii\web\View; | 11 | use yii\web\View; |
12 | 12 | ||
13 | $this->title = 'Заказ #' . $model->id; | 13 | $this->title = 'Заказ #' . $model->id; |
14 | + $this->params[ 'breadcrumbs' ][] = [ | ||
15 | + 'url' => yii\helpers\Url::to([ '/ecommerce/order/index' ]), | ||
16 | + 'label' => \Yii::t('app', 'Заказы'), | ||
17 | + ]; | ||
14 | $this->params[ 'breadcrumbs' ][] = $this->title; | 18 | $this->params[ 'breadcrumbs' ][] = $this->title; |
15 | ?> | 19 | ?> |
16 | <div class="order-update"> | 20 | <div class="order-update"> |
17 | - <h1><?php echo Html::encode($this->title) ?></h1> | 21 | + <div class="container"><h1><?php echo Html::encode($this->title) ?></h1></div> |
18 | 22 | ||
19 | <?= $this->render( | 23 | <?= $this->render( |
20 | '_form', | 24 | '_form', |
1 | +<?php | ||
2 | + | ||
3 | + use artweb\artbox\ecommerce\models\Order; | ||
4 | + use kartik\grid\GridView; | ||
5 | + use yii\helpers\Html; | ||
6 | + use yii\web\View; | ||
7 | + use yii\widgets\DetailView; | ||
8 | + | ||
9 | + /** | ||
10 | + * @var View $this | ||
11 | + * @var Order $model | ||
12 | + */ | ||
13 | + | ||
14 | + $this->title = 'Заказ #' . $model->id; | ||
15 | + $this->params[ 'breadcrumbs' ][] = [ | ||
16 | + 'label' => \Yii::t('app', 'Заказы'), | ||
17 | + 'url' => [ 'index' ], | ||
18 | + ]; | ||
19 | + $this->params[ 'breadcrumbs' ][] = $this->title; | ||
20 | +?> | ||
21 | +<div class="order-view"> | ||
22 | + | ||
23 | + <h1><?= Html::encode($this->title) ?></h1> | ||
24 | + | ||
25 | + <p> | ||
26 | + <?= Html::a( | ||
27 | + 'Update', | ||
28 | + [ | ||
29 | + 'update', | ||
30 | + 'id' => $model->id, | ||
31 | + ], | ||
32 | + [ 'class' => 'btn btn-primary' ] | ||
33 | + ) ?> | ||
34 | + | ||
35 | + </p> | ||
36 | + | ||
37 | + <?= DetailView::widget( | ||
38 | + [ | ||
39 | + 'model' => $model, | ||
40 | + 'attributes' => [ | ||
41 | + 'id', | ||
42 | + 'deadline', | ||
43 | + 'pay', | ||
44 | + 'reason', | ||
45 | + 'label', | ||
46 | + 'name', | ||
47 | + 'phone', | ||
48 | + 'email', | ||
49 | + 'comment', | ||
50 | + 'delivery', | ||
51 | + 'declaration', | ||
52 | + 'stock', | ||
53 | + 'payment', | ||
54 | + 'insurance', | ||
55 | + 'city', | ||
56 | + 'adress', | ||
57 | + 'body', | ||
58 | + 'check', | ||
59 | + 'sms', | ||
60 | + ], | ||
61 | + ] | ||
62 | + ) ?> | ||
63 | + | ||
64 | + <?php | ||
65 | + echo GridView::widget( | ||
66 | + [ | ||
67 | + 'dataProvider' => $products, | ||
68 | + 'columns' => [ | ||
69 | + 'id', | ||
70 | + 'product_name', | ||
71 | + 'name', | ||
72 | + 'sku', | ||
73 | + 'price', | ||
74 | + 'count', | ||
75 | + 'sum_cost', | ||
76 | + ], | ||
77 | + ] | ||
78 | + ); | ||
79 | + ?> | ||
80 | + | ||
81 | +</div> |