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;
+ + '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', + ] + ); +?> ++ $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