Commit bb962a6d5b8b24bcd84fa62d427864dde92da62e

Authored by Alexey Boroda
1 parent 2b29877e

-Order in process

@@ -5,8 +5,6 @@ @@ -5,8 +5,6 @@
5 use Yii; 5 use Yii;
6 use yii\behaviors\TimestampBehavior; 6 use yii\behaviors\TimestampBehavior;
7 use yii\db\ActiveRecord; 7 use yii\db\ActiveRecord;
8 - use yii\db\Expression;  
9 - use yii\web\Session;  
10 8
11 /** 9 /**
12 * Class Order 10 * Class Order
@@ -45,27 +43,38 @@ @@ -45,27 +43,38 @@
45 */ 43 */
46 class Order extends ActiveRecord 44 class Order extends ActiveRecord
47 { 45 {
48 -  
49 - const SCENARIO_QUICK = 'quick';  
50 -  
51 - private $data; 46 + const PAYMENT_LIST = [
  47 + 1 => [
  48 + 'label' => 'Оплатить наличными',
  49 + ],
  50 + 2 => [
  51 + 'label' => 'Оплатить на карту Приват Банка',
  52 + 'hint' => 'оплата поступает 30 минут до суток!',
  53 + ],
  54 + 3 => [
  55 + 'label' => 'Оплатить "Правекс-телеграф"',
  56 + 'hint' => 'оплата денежным переводом поступает от 30 мин. до 4 часов',
  57 + ],
  58 + 4 => [
  59 + 'label' => 'Оплатить по безналичному расчету',
  60 + 'hint' => 'оплата поступает на счет от 1 до 3 рабочих дней! Счет на оплату отправим сразу после обработки заказана на ваш e-mail',
  61 + ],
  62 + ];
  63 +
  64 + const SHIPPING_BY = [
  65 + 1 => [
  66 + 'label' => 'Отправитель',
  67 + ],
  68 + 2 => [
  69 + 'label' => 'Получатель',
  70 + ],
  71 + ];
52 72
53 public static function tableName() 73 public static function tableName()
54 { 74 {
55 return 'order'; 75 return 'order';
56 } 76 }
57 77
58 - public function scenarios()  
59 - {  
60 - $scenarios = array_merge(  
61 - parent::scenarios(),  
62 - [  
63 - self::SCENARIO_QUICK => [ 'phone' ],  
64 - ]  
65 - );  
66 - return $scenarios;  
67 - }  
68 -  
69 public function behaviors() 78 public function behaviors()
70 { 79 {
71 return [ 80 return [
@@ -79,6 +88,10 @@ @@ -79,6 +88,10 @@
79 { 88 {
80 return [ 89 return [
81 [ 90 [
  91 + ['pay'],
  92 + 'boolean',
  93 + ],
  94 + [
82 [ 95 [
83 'created_at', 96 'created_at',
84 'updated_at', 97 'updated_at',
@@ -94,22 +107,23 @@ @@ -94,22 +107,23 @@
94 ], 107 ],
95 [ 108 [
96 [ 'comment' ], 109 [ 'comment' ],
97 - 'safe', 110 + 'string',
98 ], 111 ],
99 [ 112 [
100 [ 'email' ], 113 [ 'email' ],
101 'email', 114 'email',
102 ], 115 ],
103 [ 116 [
104 - [ 'phone' ], 117 + [
  118 + 'phone',
  119 + 'phone2',
  120 + ],
105 'match', 121 'match',
106 'pattern' => '/^\+38\(\d{3}\)\d{3}-\d{2}-\d{2}$/', 122 'pattern' => '/^\+38\(\d{3}\)\d{3}-\d{2}-\d{2}$/',
107 - 'on' => self::SCENARIO_QUICK,  
108 ], 123 ],
109 [ 124 [
110 [ 125 [
111 'name', 126 'name',
112 - 'phone2',  
113 'numbercard', 127 'numbercard',
114 'body', 128 'body',
115 'declaration', 129 'declaration',
@@ -152,149 +166,6 @@ @@ -152,149 +166,6 @@
152 ]; 166 ];
153 } 167 }
154 168
155 - // public function beforeSave($insert)  
156 - // {  
157 - // $this->user_id = Yii::$app->user->id;  
158 - // $this->date_time = new Expression('NOW()');  
159 - // return parent::beforeSave($insert);  
160 - // }  
161 - //  
162 - // public function beforeDelete()  
163 - // {  
164 - // return parent::beforeDelete();  
165 - // }  
166 -  
167 - public function addBasket($product_variant_id, $count)  
168 - {  
169 - $session = new Session;  
170 - $session->open();  
171 - $data = $session[ 'basket' ];  
172 - $i = 0;  
173 - if (isset( $session[ 'basket' ] )) {  
174 - foreach ($session[ 'basket' ] as $key => $basket) {  
175 - if ($product_variant_id == $basket[ 'id' ]) {  
176 - $data[ $key ][ 'count' ] += $count;  
177 - $session[ 'basket' ] = $data;  
178 - $i++;  
179 - }  
180 - }  
181 - }  
182 - if ($i == 0) {  
183 - $data[] = [  
184 - 'id' => $product_variant_id,  
185 - 'count' => $count,  
186 - ];  
187 - $session[ 'basket' ] = $data;  
188 - }  
189 - }  
190 -  
191 - public function rowBasket()  
192 - {  
193 - $session = new Session;  
194 - $session->open();  
195 - $cost = 0;  
196 - $count = 0;  
197 - if (isset( $session[ 'basket' ] ) && count($session[ 'basket' ])) {  
198 - foreach ($session[ 'basket' ] as $product) {  
199 - $count += $product[ 'count' ];  
200 - }  
201 - }  
202 -  
203 - return (object) [  
204 - 'cost' => $cost,  
205 - 'count' => $count,  
206 - ];  
207 - }  
208 -  
209 - public function deleteBasketMod($id)  
210 - {  
211 - $session = new Session;  
212 - $session->open();  
213 - $basket = $session[ 'basket' ];  
214 - foreach ($basket as $key => $product) {  
215 - if ($id == $product[ 'id' ]) {  
216 - unset( $basket[ $key ] );  
217 - }  
218 - }  
219 - $session[ 'basket' ] = $basket;  
220 - }  
221 -  
222 - public function updateBasket($row)  
223 - {  
224 - $session = new Session;  
225 - $session->open();  
226 - //$data = array();  
227 - if ($row[ 'count' ] > 0) {  
228 - $this->data[] = [  
229 - 'id' => $row[ 'id' ],  
230 - 'count' => $row[ 'count' ],  
231 - ];  
232 - }  
233 - $session[ 'basket' ] = $this->data;  
234 - }  
235 -  
236 - public function getBasketMods()  
237 - {  
238 - $session = new Session;  
239 - $session->open();  
240 - $products = [];  
241 - if (empty( $session[ 'basket' ] )) {  
242 - return [];  
243 - }  
244 - foreach ($session[ 'basket' ] as $product) {  
245 - $row = ProductVariant::find()  
246 - ->select(  
247 - [  
248 - 'product_variant.*',  
249 - 'product.name as productName',  
250 - 'product.alias',  
251 - ]  
252 - )  
253 - ->where([ 'product_variant.id' => $product[ 'id' ] ])  
254 - ->leftJoin('product', 'product.id = product_variant.product_id')  
255 - ->one();  
256 - $row->count = $product[ 'count' ];  
257 - $row->sum_cost = $product[ 'count' ] * $row->price;  
258 - $products[] = $row;  
259 - }  
260 -  
261 - return $products;  
262 - }  
263 -  
264 - public function getSumCost()  
265 - {  
266 - $session = new Session;  
267 - $session->open();  
268 - $cost = 0;  
269 - if (empty( $session[ 'basket' ] )) {  
270 - return false;  
271 - }  
272 - foreach ($session[ 'basket' ] as $product) {  
273 - $cost += ( $this->getModCost($product[ 'id' ]) * $product[ 'count' ] );  
274 - }  
275 -  
276 - return $cost;  
277 - }  
278 -  
279 - private function getModCost($product_variant_id)  
280 - {  
281 - /**  
282 - * @var ProductVariant $mod  
283 - */  
284 - $mod = ProductVariant::find()  
285 - ->where([ 'id' => $product_variant_id ])  
286 - ->one();  
287 -  
288 - return $mod->price;  
289 - }  
290 -  
291 - public function clearBasket()  
292 - {  
293 - $session = new Session;  
294 - $session->open();  
295 - $session[ 'basket' ] = NULL;  
296 - }  
297 -  
298 public function getUser() 169 public function getUser()
299 { 170 {
300 return $this->hasOne(Customer::className(), [ 'id' => 'user_id' ]); 171 return $this->hasOne(Customer::className(), [ 'id' => 'user_id' ]);
models/OrderSearch.php
@@ -38,6 +38,7 @@ @@ -38,6 +38,7 @@
38 'date_from', 38 'date_from',
39 'date_to', 39 'date_to',
40 'date_range', 40 'date_range',
  41 + 'created_at'
41 ], 42 ],
42 'safe', 43 'safe',
43 ], 44 ],
@@ -73,7 +74,7 @@ @@ -73,7 +74,7 @@
73 ); 74 );
74 75
75 $this->load($params); 76 $this->load($params);
76 - 77 +
77 if (!$this->validate()) { 78 if (!$this->validate()) {
78 // uncomment the following line if you do not want to return any records when validation fails 79 // uncomment the following line if you do not want to return any records when validation fails
79 // $query->where('0=1'); 80 // $query->where('0=1');
@@ -112,9 +113,25 @@ @@ -112,9 +113,25 @@
112 $this->phone, 113 $this->phone,
113 ] 114 ]
114 ); 115 );
115 -  
116 - $query->andFilterWhere(['>=', 'date_time', $this->date_from]);  
117 - $query->andFilterWhere(['<=', 'date_time', $this->date_to]); 116 + if (!empty($this->date_range)) {
  117 + $this->date_from = strtotime(explode('to', $this->date_range)[ 0 ]);
  118 + $this->date_to = strtotime(explode('to', $this->date_range)[ 1 ]);
  119 +
  120 + $query->andFilterWhere(
  121 + [
  122 + '>=',
  123 + 'created_at',
  124 + $this->date_from,
  125 + ]
  126 + );
  127 + $query->andFilterWhere(
  128 + [
  129 + '<=',
  130 + 'created_at',
  131 + $this->date_to,
  132 + ]
  133 + );
  134 + }
118 135
119 return $dataProvider; 136 return $dataProvider;
120 } 137 }
views/order/_form.php
1 <?php 1 <?php
2 2
  3 + use artweb\artbox\ecommerce\models\Label;
3 use artweb\artbox\ecommerce\models\Order; 4 use artweb\artbox\ecommerce\models\Order;
4 use artweb\artbox\ecommerce\models\OrderProduct; 5 use artweb\artbox\ecommerce\models\OrderProduct;
5 - use frontend\models\OrderFrontend;  
6 use kartik\grid\GridView; 6 use kartik\grid\GridView;
  7 + use kartik\widgets\DatePicker;
7 use kartik\widgets\Select2; 8 use kartik\widgets\Select2;
  9 + use kartik\widgets\SwitchInput;
8 use yii\data\ActiveDataProvider; 10 use yii\data\ActiveDataProvider;
9 use yii\helpers\Html; 11 use yii\helpers\Html;
10 use yii\bootstrap\ActiveForm; 12 use yii\bootstrap\ActiveForm;
@@ -41,6 +43,15 @@ $(document).on(&#39;submit&#39;, &#39;#add-product-form&#39;, function(e) { @@ -41,6 +43,15 @@ $(document).on(&#39;submit&#39;, &#39;#add-product-form&#39;, function(e) {
41 JS; 43 JS;
42 44
43 $this->registerJs($js, View::POS_READY); 45 $this->registerJs($js, View::POS_READY);
  46 +
  47 + $js = <<< JS
  48 +$('#order-phone, #order-phone2').mask('+38(000)000-00-00', {
  49 + placeholder: '+38(___)___-__-__'
  50 +});
  51 +JS;
  52 +
  53 + $this->registerJs($js, View::POS_READY);
  54 +
44 ?> 55 ?>
45 56
46 <?php $form = ActiveForm::begin(); ?> 57 <?php $form = ActiveForm::begin(); ?>
@@ -56,6 +67,34 @@ JS; @@ -56,6 +67,34 @@ JS;
56 <div class="row"> 67 <div class="row">
57 <div class="col-sm-6"> 68 <div class="col-sm-6">
58 69
  70 + <?= $form->field($model, 'deadline')->widget(DatePicker::className(), [
  71 +
  72 + ])?>
  73 +
  74 + <?php
  75 + echo $form->field($model, 'pay')
  76 + ->widget(
  77 + SwitchInput::className(),
  78 + [
  79 + 'name' => 'pay',
  80 + 'pluginOptions' => [
  81 + 'onText' => \Yii::t('app', 'Оплачено'),
  82 + 'offText' => \Yii::t('app', 'Не оплачено'),
  83 + ],
  84 + ]
  85 + ); ?>
  86 +
  87 + <?= $form->field($model, 'label')
  88 + ->dropDownList(
  89 + ArrayHelper::map(
  90 + Label::find()
  91 + ->asArray()
  92 + ->all(),
  93 + 'id',
  94 + 'label'
  95 + ),
  96 + [ 'prompt' => 'Метка' ]
  97 + ); ?>
59 98
60 <?= $form->field($model, 'name') ?> 99 <?= $form->field($model, 'name') ?>
61 100
@@ -67,63 +106,49 @@ JS; @@ -67,63 +106,49 @@ JS;
67 106
68 <?= $form->field($model, 'numbercard') ?> 107 <?= $form->field($model, 'numbercard') ?>
69 108
70 - <?= $form->field($model, 'body') 109 + <?= $form->field($model, 'comment')
71 ->textarea([ 'rows' => '3' ]) ?> 110 ->textarea([ 'rows' => '3' ]) ?>
72 -  
73 - <?php $form->field($model, 'delivery')  
74 - ->dropDownList(  
75 - ArrayHelper::map(  
76 - Delivery::find()  
77 - ->asArray()  
78 - ->all(),  
79 - 'id',  
80 - 'title'  
81 - )  
82 - ) ?> 111 + <?= $form->field($model, 'delivery')
  112 + ->dropDownList(
  113 + ArrayHelper::map(
  114 + Delivery::find()
  115 + ->joinWith('lang')
  116 + ->asArray()
  117 + ->all(),
  118 + 'id',
  119 + 'lang.title'
  120 + ),
  121 + [ 'prompt' => \Yii::t('app', 'Выберите доставку ...') ]
  122 + ) ?>
  123 +
  124 + </div>
  125 + <div class="col-sm-6">
83 126
84 <?= $form->field($model, 'declaration') ?> 127 <?= $form->field($model, 'declaration') ?>
85 128
86 <?= $form->field($model, 'stock') ?> 129 <?= $form->field($model, 'stock') ?>
87 130
88 - <?= $form->field($model, 'consignment') ?>  
89 - </div>  
90 - <div class="col-sm-6">  
91 -  
92 <?= $form->field($model, 'payment') 131 <?= $form->field($model, 'payment')
93 ->dropDownList( 132 ->dropDownList(
94 - ArrayHelper::getColumn(OrderFrontend::PAYMENT_LIST, 'label'),  
95 - [ 'prompt' => '...' ] 133 + ArrayHelper::getColumn(Order::PAYMENT_LIST, 'label'),
  134 + [ 'prompt' => 'Способ оплаты ...' ]
96 ); ?> 135 ); ?>
97 136
98 <?= $form->field($model, 'insurance') ?> 137 <?= $form->field($model, 'insurance') ?>
99 138
100 <?= $form->field($model, 'amount_imposed') ?> 139 <?= $form->field($model, 'amount_imposed') ?>
101 140
102 - <?= $form->field($model, 'shipping_by') ?> 141 + <?= $form->field($model, 'shipping_by')
  142 + ->dropDownList(
  143 + ArrayHelper::getColumn(Order::SHIPPING_BY, 'label'),
  144 + [ 'prompt' => 'Оплата доставки ...' ]
  145 + ); ?>
103 146
104 <?= $form->field($model, 'city') ?> 147 <?= $form->field($model, 'city') ?>
105 148
106 <?= $form->field($model, 'adress') ?> 149 <?= $form->field($model, 'adress') ?>
107 150
108 -  
109 - <?= $form->field($model, 'total') ?>  
110 -  
111 - <?= $form->field($model, 'status')  
112 - ->dropDownList(  
113 - [  
114 - 'Нет' => 'Нет',  
115 - 'Обработан' => 'Обработан',  
116 - 'На комплектации' => 'На комплектации',  
117 - 'Укомплектован' => 'Укомплектован',  
118 - 'Доставка' => 'Доставка',  
119 - 'Выполнен' => 'Выполнен',  
120 - 'Резерв оплачен' => 'Резерв оплачен',  
121 - 'Резерв неоплачен' => 'Резерв неоплачен',  
122 - ],  
123 - [ 'prompt' => '...' ]  
124 - ); ?>  
125 -  
126 - <?= $form->field($model, 'comment') 151 + <?= $form->field($model, 'body')
127 ->textarea([ 'rows' => '3' ]) ?> 152 ->textarea([ 'rows' => '3' ]) ?>
128 </div> 153 </div>
129 </div> 154 </div>
@@ -137,7 +162,7 @@ JS; @@ -137,7 +162,7 @@ JS;
137 echo GridView::widget( 162 echo GridView::widget(
138 [ 163 [
139 'dataProvider' => $dataProvider, 164 'dataProvider' => $dataProvider,
140 - 'layout' => '{items}{pager}', 165 + 'layout' => '{items}{pager}',
141 'columns' => [ 166 'columns' => [
142 'id', 167 'id',
143 'product_name', 168 'product_name',
@@ -172,7 +197,7 @@ JS; @@ -172,7 +197,7 @@ JS;
172 'pjaxSettings' => [ 197 'pjaxSettings' => [
173 'options' => [ 198 'options' => [
174 'scrollTo' => 'false', 199 'scrollTo' => 'false',
175 - 'id' => 'order-products-grid', 200 + 'id' => 'order-products-grid',
176 ], 201 ],
177 ], 202 ],
178 ] 203 ]
@@ -199,7 +224,7 @@ JS; @@ -199,7 +224,7 @@ JS;
199 'options' => [ 'placeholder' => 'Search for a product ...' ], 224 'options' => [ 'placeholder' => 'Search for a product ...' ],
200 'pluginOptions' => [ 225 'pluginOptions' => [
201 'allowClear' => true, 226 'allowClear' => true,
202 - 'disabled' => $model->isNewRecord ? true : false, 227 + 'disabled' => $model->isNewRecord ? true : false,
203 'minimumInputLength' => 3, 228 'minimumInputLength' => 3,
204 'language' => [ 229 'language' => [
205 'errorLoading' => new JsExpression( 230 'errorLoading' => new JsExpression(
@@ -229,7 +254,8 @@ JS; @@ -229,7 +254,8 @@ JS;
229 ?> 254 ?>
230 </div> 255 </div>
231 <div class="col-md-2"> 256 <div class="col-md-2">
232 - <?php echo $newProductForm->field($newOrderProduct, 'count')->input('number'); ?> 257 + <?php echo $newProductForm->field($newOrderProduct, 'count')
  258 + ->input('number'); ?>
233 </div> 259 </div>
234 <div class="col-md-2"> 260 <div class="col-md-2">
235 <?php echo Html::submitButton( 261 <?php echo Html::submitButton(
views/order/index.php
@@ -5,12 +5,17 @@ @@ -5,12 +5,17 @@
5 * @var View $this 5 * @var View $this
6 */ 6 */
7 7
  8 + use artweb\artbox\ecommerce\models\Delivery;
  9 + use artweb\artbox\ecommerce\models\Label;
8 use artweb\artbox\ecommerce\models\OrderSearch; 10 use artweb\artbox\ecommerce\models\OrderSearch;
9 use kartik\daterange\DateRangePicker; 11 use kartik\daterange\DateRangePicker;
  12 + use kartik\select2\Select2;
10 use yii\data\ActiveDataProvider; 13 use yii\data\ActiveDataProvider;
11 use yii\helpers\Html; 14 use yii\helpers\Html;
12 - use kartik\grid\GridView; 15 + use yii\grid\GridView;
  16 + use yii\helpers\Url;
13 use yii\web\View; 17 use yii\web\View;
  18 + use yii\widgets\ActiveForm;
14 19
15 $this->title = 'Заказы'; 20 $this->title = 'Заказы';
16 $this->params[ 'breadcrumbs' ][] = $this->title; 21 $this->params[ 'breadcrumbs' ][] = $this->title;
@@ -20,32 +25,109 @@ @@ -20,32 +25,109 @@
20 <?= Html::a('Add order', [ 'create' ], [ 'class' => 'btn btn-success' ]) ?> 25 <?= Html::a('Add order', [ 'create' ], [ 'class' => 'btn btn-success' ]) ?>
21 </p> 26 </p>
22 27
23 -<?= GridView::widget(  
24 - [  
25 - 'dataProvider' => $dataProvider,  
26 - 'filterModel' => $searchModel,  
27 - 'columns' => [  
28 - 'id',  
29 - [  
30 - 'attribute' => 'date_time',  
31 - 'filter' => DateRangePicker::widget(  
32 - [  
33 - 'name' => 'OrderSearch[date_range]',  
34 - 'model' => $searchModel,  
35 - 'convertFormat' => false,  
36 - 'pluginOptions' => [  
37 - 'format' => 'YYYY-MM-DD',  
38 - 'opens' => 'left',  
39 - ],  
40 - ]  
41 - ), 28 +<?php
  29 + $searchForm = ActiveForm::begin(
  30 + [
  31 + 'method' => 'GET',
  32 + 'action' => Url::to([ 'order/index' ]),
  33 + 'id' => 'search-form',
  34 + ]
  35 + );
  36 +?>
  37 +
  38 +<p>
  39 +
  40 + <?php echo Html::submitButton(
  41 + 'Search',
  42 + [
  43 + 'class' => 'btn btn-primary',
  44 + ]
  45 + ) ?>
  46 +
  47 +</p>
  48 +
  49 +<?php
  50 + echo Select2::widget(
  51 + [
  52 + 'model' => $searchModel,
  53 + 'attribute' => 'label',
  54 + 'data' => Label::find()
  55 + ->joinWith('lang')
  56 + ->select(['CONCAT(order_label.label,order_label_lang.title) AS name', 'id'])
  57 + ->indexBy('id')
  58 + ->asArray()
  59 + ->column(),
  60 + 'options' => [ 'placeholder' => 'Select a state ...' ],
  61 + 'pluginOptions' => [
  62 + 'allowClear' => true,
  63 + 'multiple' => true,
42 ], 64 ],
43 - 'name',  
44 - 'phone',  
45 - 'status',  
46 - [  
47 - 'class' => 'yii\grid\ActionColumn', 65 + ]
  66 + );
  67 +?>
  68 +<br>
  69 +<?php
  70 + echo Select2::widget(
  71 + [
  72 + 'model' => $searchModel,
  73 + 'attribute' => 'delivery',
  74 + 'data' => Delivery::find()
  75 + ->joinWith('lang')
  76 + ->select('order_delivery_lang.title, id')
  77 + ->indexBy('id')
  78 + ->asArray()
  79 + ->column(),
  80 + 'options' => [ 'placeholder' => 'Select a state ...' ],
  81 + 'pluginOptions' => [
  82 + 'allowClear' => true,
  83 + 'multiple' => true,
  84 + ],
  85 + ]
  86 + );
  87 +?>
  88 +<p>
  89 +<?php
  90 + echo GridView::widget(
  91 + [
  92 + 'dataProvider' => $dataProvider,
  93 + 'filterModel' => $searchModel,
  94 + 'columns' => [
  95 + [
  96 + 'attribute' => 'id',
  97 + 'filter' => $searchForm->field($searchModel, 'id')
  98 + ->textInput(),
  99 + ],
  100 + [
  101 + 'attribute' => 'created_at',
  102 + 'format' => 'date',
  103 + 'filter' => $searchForm->field($searchModel, 'date_range')
  104 + ->widget(
  105 + DateRangePicker::className(),
  106 + [
  107 + 'convertFormat' => false,
  108 + 'pluginOptions' => [
  109 + 'locale' => [
  110 + 'format' => 'D-M-Y',
  111 + 'separator' => ' to ',
  112 + ],
  113 + 'opens' => 'left',
  114 + ],
  115 + ]
  116 + )
  117 + ->label(false)
  118 + ->render(),
  119 + ],
  120 + 'name',
  121 + 'phone',
  122 + 'status',
  123 + [
  124 + 'class' => 'yii\grid\ActionColumn',
  125 + ],
48 ], 126 ],
49 - ],  
50 - ]  
51 -) ?> 127 + ]
  128 + );
  129 +?>
  130 +</p>
  131 +<?php
  132 + ActiveForm::end();
  133 +?>