From bb962a6d5b8b24bcd84fa62d427864dde92da62e Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 23 Nov 2016 19:34:15 +0200 Subject: [PATCH] -Order in process --- models/Order.php | 199 +++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------- models/OrderSearch.php | 25 +++++++++++++++++++++---- views/order/_form.php | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------- views/order/index.php | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- 4 files changed, 235 insertions(+), 239 deletions(-) diff --git a/models/Order.php b/models/Order.php index 0b93dd4..8a86d5e 100755 --- a/models/Order.php +++ b/models/Order.php @@ -5,8 +5,6 @@ use Yii; use yii\behaviors\TimestampBehavior; use yii\db\ActiveRecord; - use yii\db\Expression; - use yii\web\Session; /** * Class Order @@ -45,27 +43,38 @@ */ class Order extends ActiveRecord { - - const SCENARIO_QUICK = 'quick'; - - private $data; + const PAYMENT_LIST = [ + 1 => [ + 'label' => 'Оплатить наличными', + ], + 2 => [ + 'label' => 'Оплатить на карту Приват Банка', + 'hint' => 'оплата поступает 30 минут до суток!', + ], + 3 => [ + 'label' => 'Оплатить "Правекс-телеграф"', + 'hint' => 'оплата денежным переводом поступает от 30 мин. до 4 часов', + ], + 4 => [ + 'label' => 'Оплатить по безналичному расчету', + 'hint' => 'оплата поступает на счет от 1 до 3 рабочих дней! Счет на оплату отправим сразу после обработки заказана на ваш e-mail', + ], + ]; + + const SHIPPING_BY = [ + 1 => [ + 'label' => 'Отправитель', + ], + 2 => [ + 'label' => 'Получатель', + ], + ]; public static function tableName() { return 'order'; } - public function scenarios() - { - $scenarios = array_merge( - parent::scenarios(), - [ - self::SCENARIO_QUICK => [ 'phone' ], - ] - ); - return $scenarios; - } - public function behaviors() { return [ @@ -79,6 +88,10 @@ { return [ [ + ['pay'], + 'boolean', + ], + [ [ 'created_at', 'updated_at', @@ -94,22 +107,23 @@ ], [ [ 'comment' ], - 'safe', + 'string', ], [ [ 'email' ], 'email', ], [ - [ 'phone' ], + [ + 'phone', + 'phone2', + ], 'match', 'pattern' => '/^\+38\(\d{3}\)\d{3}-\d{2}-\d{2}$/', - 'on' => self::SCENARIO_QUICK, ], [ [ 'name', - 'phone2', 'numbercard', 'body', 'declaration', @@ -152,149 +166,6 @@ ]; } - // public function beforeSave($insert) - // { - // $this->user_id = Yii::$app->user->id; - // $this->date_time = new Expression('NOW()'); - // return parent::beforeSave($insert); - // } - // - // public function beforeDelete() - // { - // return parent::beforeDelete(); - // } - - public function addBasket($product_variant_id, $count) - { - $session = new Session; - $session->open(); - $data = $session[ 'basket' ]; - $i = 0; - if (isset( $session[ 'basket' ] )) { - foreach ($session[ 'basket' ] as $key => $basket) { - if ($product_variant_id == $basket[ 'id' ]) { - $data[ $key ][ 'count' ] += $count; - $session[ 'basket' ] = $data; - $i++; - } - } - } - if ($i == 0) { - $data[] = [ - 'id' => $product_variant_id, - 'count' => $count, - ]; - $session[ 'basket' ] = $data; - } - } - - public function rowBasket() - { - $session = new Session; - $session->open(); - $cost = 0; - $count = 0; - if (isset( $session[ 'basket' ] ) && count($session[ 'basket' ])) { - foreach ($session[ 'basket' ] as $product) { - $count += $product[ 'count' ]; - } - } - - return (object) [ - 'cost' => $cost, - 'count' => $count, - ]; - } - - public function deleteBasketMod($id) - { - $session = new Session; - $session->open(); - $basket = $session[ 'basket' ]; - foreach ($basket as $key => $product) { - if ($id == $product[ 'id' ]) { - unset( $basket[ $key ] ); - } - } - $session[ 'basket' ] = $basket; - } - - public function updateBasket($row) - { - $session = new Session; - $session->open(); - //$data = array(); - if ($row[ 'count' ] > 0) { - $this->data[] = [ - 'id' => $row[ 'id' ], - 'count' => $row[ 'count' ], - ]; - } - $session[ 'basket' ] = $this->data; - } - - public function getBasketMods() - { - $session = new Session; - $session->open(); - $products = []; - if (empty( $session[ 'basket' ] )) { - return []; - } - foreach ($session[ 'basket' ] as $product) { - $row = ProductVariant::find() - ->select( - [ - 'product_variant.*', - 'product.name as productName', - 'product.alias', - ] - ) - ->where([ 'product_variant.id' => $product[ 'id' ] ]) - ->leftJoin('product', 'product.id = product_variant.product_id') - ->one(); - $row->count = $product[ 'count' ]; - $row->sum_cost = $product[ 'count' ] * $row->price; - $products[] = $row; - } - - return $products; - } - - public function getSumCost() - { - $session = new Session; - $session->open(); - $cost = 0; - if (empty( $session[ 'basket' ] )) { - return false; - } - foreach ($session[ 'basket' ] as $product) { - $cost += ( $this->getModCost($product[ 'id' ]) * $product[ 'count' ] ); - } - - return $cost; - } - - private function getModCost($product_variant_id) - { - /** - * @var ProductVariant $mod - */ - $mod = ProductVariant::find() - ->where([ 'id' => $product_variant_id ]) - ->one(); - - return $mod->price; - } - - public function clearBasket() - { - $session = new Session; - $session->open(); - $session[ 'basket' ] = NULL; - } - public function getUser() { return $this->hasOne(Customer::className(), [ 'id' => 'user_id' ]); diff --git a/models/OrderSearch.php b/models/OrderSearch.php index 94364de..a5b667c 100755 --- a/models/OrderSearch.php +++ b/models/OrderSearch.php @@ -38,6 +38,7 @@ 'date_from', 'date_to', 'date_range', + 'created_at' ], 'safe', ], @@ -73,7 +74,7 @@ ); $this->load($params); - + if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); @@ -112,9 +113,25 @@ $this->phone, ] ); - - $query->andFilterWhere(['>=', 'date_time', $this->date_from]); - $query->andFilterWhere(['<=', 'date_time', $this->date_to]); + if (!empty($this->date_range)) { + $this->date_from = strtotime(explode('to', $this->date_range)[ 0 ]); + $this->date_to = strtotime(explode('to', $this->date_range)[ 1 ]); + + $query->andFilterWhere( + [ + '>=', + 'created_at', + $this->date_from, + ] + ); + $query->andFilterWhere( + [ + '<=', + 'created_at', + $this->date_to, + ] + ); + } return $dataProvider; } diff --git a/views/order/_form.php b/views/order/_form.php index 9e07a01..bc5e2f4 100755 --- a/views/order/_form.php +++ b/views/order/_form.php @@ -1,10 +1,12 @@ registerJs($js, View::POS_READY); + + $js = <<< JS +$('#order-phone, #order-phone2').mask('+38(000)000-00-00', { + placeholder: '+38(___)___-__-__' +}); +JS; + + $this->registerJs($js, View::POS_READY); + ?> @@ -56,6 +67,34 @@ JS;
+ field($model, 'deadline')->widget(DatePicker::className(), [ + + ])?> + + field($model, 'pay') + ->widget( + SwitchInput::className(), + [ + 'name' => 'pay', + 'pluginOptions' => [ + 'onText' => \Yii::t('app', 'Оплачено'), + 'offText' => \Yii::t('app', 'Не оплачено'), + ], + ] + ); ?> + + field($model, 'label') + ->dropDownList( + ArrayHelper::map( + Label::find() + ->asArray() + ->all(), + 'id', + 'label' + ), + [ 'prompt' => 'Метка' ] + ); ?> field($model, 'name') ?> @@ -67,63 +106,49 @@ JS; field($model, 'numbercard') ?> - field($model, 'body') + field($model, 'comment') ->textarea([ 'rows' => '3' ]) ?> - - field($model, 'delivery') - ->dropDownList( - ArrayHelper::map( - Delivery::find() - ->asArray() - ->all(), - 'id', - 'title' - ) - ) ?> + field($model, 'delivery') + ->dropDownList( + ArrayHelper::map( + Delivery::find() + ->joinWith('lang') + ->asArray() + ->all(), + 'id', + 'lang.title' + ), + [ 'prompt' => \Yii::t('app', 'Выберите доставку ...') ] + ) ?> + +
+
field($model, 'declaration') ?> field($model, 'stock') ?> - field($model, 'consignment') ?> -
-
- field($model, 'payment') ->dropDownList( - ArrayHelper::getColumn(OrderFrontend::PAYMENT_LIST, 'label'), - [ 'prompt' => '...' ] + ArrayHelper::getColumn(Order::PAYMENT_LIST, 'label'), + [ 'prompt' => 'Способ оплаты ...' ] ); ?> field($model, 'insurance') ?> field($model, 'amount_imposed') ?> - field($model, 'shipping_by') ?> + field($model, 'shipping_by') + ->dropDownList( + ArrayHelper::getColumn(Order::SHIPPING_BY, 'label'), + [ 'prompt' => 'Оплата доставки ...' ] + ); ?> field($model, 'city') ?> field($model, 'adress') ?> - - field($model, 'total') ?> - - field($model, 'status') - ->dropDownList( - [ - 'Нет' => 'Нет', - 'Обработан' => 'Обработан', - 'На комплектации' => 'На комплектации', - 'Укомплектован' => 'Укомплектован', - 'Доставка' => 'Доставка', - 'Выполнен' => 'Выполнен', - 'Резерв оплачен' => 'Резерв оплачен', - 'Резерв неоплачен' => 'Резерв неоплачен', - ], - [ 'prompt' => '...' ] - ); ?> - - field($model, 'comment') + field($model, 'body') ->textarea([ 'rows' => '3' ]) ?>
@@ -137,7 +162,7 @@ JS; echo GridView::widget( [ 'dataProvider' => $dataProvider, - 'layout' => '{items}{pager}', + 'layout' => '{items}{pager}', 'columns' => [ 'id', 'product_name', @@ -172,7 +197,7 @@ JS; 'pjaxSettings' => [ 'options' => [ 'scrollTo' => 'false', - 'id' => 'order-products-grid', + 'id' => 'order-products-grid', ], ], ] @@ -199,7 +224,7 @@ JS; 'options' => [ 'placeholder' => 'Search for a product ...' ], 'pluginOptions' => [ 'allowClear' => true, - 'disabled' => $model->isNewRecord ? true : false, + 'disabled' => $model->isNewRecord ? true : false, 'minimumInputLength' => 3, 'language' => [ 'errorLoading' => new JsExpression( @@ -229,7 +254,8 @@ JS; ?>
- field($newOrderProduct, 'count')->input('number'); ?> + field($newOrderProduct, 'count') + ->input('number'); ?>
title = 'Заказы'; $this->params[ 'breadcrumbs' ][] = $this->title; @@ -20,32 +25,109 @@ 'btn btn-success' ]) ?>

- $dataProvider, - 'filterModel' => $searchModel, - 'columns' => [ - 'id', - [ - 'attribute' => 'date_time', - 'filter' => DateRangePicker::widget( - [ - 'name' => 'OrderSearch[date_range]', - 'model' => $searchModel, - 'convertFormat' => false, - 'pluginOptions' => [ - 'format' => 'YYYY-MM-DD', - 'opens' => 'left', - ], - ] - ), + 'GET', + 'action' => Url::to([ 'order/index' ]), + 'id' => 'search-form', + ] + ); +?> + +

+ + 'btn btn-primary', + ] + ) ?> + +

+ + $searchModel, + 'attribute' => 'label', + 'data' => Label::find() + ->joinWith('lang') + ->select(['CONCAT(order_label.label,order_label_lang.title) AS name', 'id']) + ->indexBy('id') + ->asArray() + ->column(), + 'options' => [ 'placeholder' => 'Select a state ...' ], + 'pluginOptions' => [ + 'allowClear' => true, + 'multiple' => true, ], - 'name', - 'phone', - 'status', - [ - 'class' => 'yii\grid\ActionColumn', + ] + ); +?> +
+ $searchModel, + 'attribute' => 'delivery', + 'data' => Delivery::find() + ->joinWith('lang') + ->select('order_delivery_lang.title, id') + ->indexBy('id') + ->asArray() + ->column(), + 'options' => [ 'placeholder' => 'Select a state ...' ], + 'pluginOptions' => [ + 'allowClear' => true, + 'multiple' => true, + ], + ] + ); +?> +

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + [ + 'attribute' => 'id', + 'filter' => $searchForm->field($searchModel, 'id') + ->textInput(), + ], + [ + 'attribute' => 'created_at', + 'format' => 'date', + 'filter' => $searchForm->field($searchModel, 'date_range') + ->widget( + DateRangePicker::className(), + [ + 'convertFormat' => false, + 'pluginOptions' => [ + 'locale' => [ + 'format' => 'D-M-Y', + 'separator' => ' to ', + ], + 'opens' => 'left', + ], + ] + ) + ->label(false) + ->render(), + ], + 'name', + 'phone', + 'status', + [ + 'class' => 'yii\grid\ActionColumn', + ], ], - ], - ] -) ?> + ] + ); +?> +

+ -- libgit2 0.21.4