From 0118578668ca12fa0e7c61807059ac4b09e9e00c Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 24 Nov 2016 21:10:39 +0200 Subject: [PATCH] -Sms in process --- controllers/OrderController.php | 4 ++-- models/Order.php | 45 +++++++++++++++++++++++++++++++-------------- models/OrderProduct.php | 7 +++++++ models/OrderSearch.php | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- models/TaxGroup.php | 4 ++-- views/order/_form.php | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- views/order/index.php | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------- 7 files changed, 302 insertions(+), 95 deletions(-) diff --git a/controllers/OrderController.php b/controllers/OrderController.php index d5409d9..5d723ff 100755 --- a/controllers/OrderController.php +++ b/controllers/OrderController.php @@ -202,7 +202,7 @@ $dataProvider = new ActiveDataProvider( [ - 'query' => $model->getProducts(), + 'query' => $model->getProducts()->joinWith('productVariant'), ] ); @@ -271,7 +271,7 @@ $dataProvider = new ActiveDataProvider( [ - 'query' => $model->getProducts(), + 'query' => $model->getProducts()->joinWith('productVariant.product.brand'), ] ); diff --git a/models/Order.php b/models/Order.php index 8ce9a07..4cf4380 100755 --- a/models/Order.php +++ b/models/Order.php @@ -2,6 +2,7 @@ namespace artweb\artbox\ecommerce\models; use artweb\artbox\models\Customer; + use common\models\User; use Yii; use yii\behaviors\TimestampBehavior; use yii\db\ActiveRecord; @@ -20,6 +21,7 @@ * @property string $check * @property string $sms * @property int $id + * @property integer $manager_id * @property int $user_id * @property string $name * @property string $phone @@ -88,10 +90,15 @@ 'payment', 'reason', 'label', + 'manager_id', ], 'integer', ], [ + [ 'total' ], + 'double', + ], + [ [ 'phone', ], @@ -127,7 +134,6 @@ 'shipping_by', 'city', 'adress', - 'total', 'status', 'check', 'sms', @@ -170,17 +176,19 @@ public function attributeLabels() { return [ - 'name' => Yii::t('app', 'order_name'), - 'phone' => Yii::t('app', 'order_phone'), - 'email' => Yii::t('app', 'order_email'), - 'comment' => Yii::t('app', 'order_comment'), - 'created_at' => Yii::t('app', 'Дата добавления'), - 'updated_at' => Yii::t('app', 'Дата обновления'), - 'deleted_at' => Yii::t('app', 'Дата удаления'), - 'deadline' => Yii::t('app', 'Дедлайн'), - 'reason' => Yii::t('app', 'Причина'), - 'check' => Yii::t('app', 'Чек'), - 'sms' => Yii::t('app', 'СМС'), + 'name' => Yii::t('app', 'order_name'), + 'phone' => Yii::t('app', 'order_phone'), + 'email' => Yii::t('app', 'order_email'), + 'comment' => Yii::t('app', 'order_comment'), + 'created_at' => Yii::t('app', 'Дата добавления'), + 'updated_at' => Yii::t('app', 'Дата обновления'), + 'deleted_at' => Yii::t('app', 'Дата удаления'), + 'deadline' => Yii::t('app', 'Дедлайн'), + 'reason' => Yii::t('app', 'Причина'), + 'check' => Yii::t('app', 'Чек'), + 'sms' => Yii::t('app', 'СМС'), + 'consignment' => Yii::t('app', 'Номер накладной'), + 'manager_id' => Yii::t('app', 'Менеджер'), ]; } @@ -236,18 +244,27 @@ return ''; } } - + /** * If deadline is fucked up returns true, * if deadline is not setted return false, like everything is ok + * * @return bool */ public function getWasted() { - if (empty($this->deadline)) { + if (empty( $this->deadline )) { return false; } else { return time() > strtotime($this->deadline); } } + + /** + * + */ + public function getManager() + { + $this->hasOne(User::className(), [ 'id' => 'manager_id' ]); + } } \ No newline at end of file diff --git a/models/OrderProduct.php b/models/OrderProduct.php index ce36314..1f308b3 100755 --- a/models/OrderProduct.php +++ b/models/OrderProduct.php @@ -29,6 +29,13 @@ return 'order_product'; } + public function beforeSave($insert) + { + $this->price = $this->productVariant->price; + $this->sum_cost = $this->price * $this->count; + return parent::beforeSave($insert); // TODO: Change the autogenerated stub + } + public function rules() { return [ diff --git a/models/OrderSearch.php b/models/OrderSearch.php index a5b667c..1fe71cb 100755 --- a/models/OrderSearch.php +++ b/models/OrderSearch.php @@ -4,6 +4,7 @@ use yii\base\Model; use yii\data\ActiveDataProvider; + use yii\helpers\VarDumper; /** * OrderSearch represents the model behind the search form about `\artweb\artbox\ecommerce\models\Order`. @@ -13,6 +14,7 @@ public $date_from; public $date_to; public $date_range; + public $sku; /** * @inheritdoc @@ -23,10 +25,7 @@ [ [ 'id', - 'user_id', - 'delivery', - 'payment', - 'status', + 'manager_id', ], 'integer', ], @@ -38,7 +37,13 @@ 'date_from', 'date_to', 'date_range', - 'created_at' + 'created_at', + 'body', + 'declaration', + 'consignment', + 'delivery', + 'label', + 'sku', ], 'safe', ], @@ -75,20 +80,27 @@ $this->load($params); + // VarDumper::dump($params, 10, true); die(); + if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } + if (!empty( $this->sku )) { + $query->innerJoinWith('products.productVariant') + ->andWhere( + [ + 'product_variant.id' => $this->sku, + ] + ); + } + // grid filtering conditions $query->andFilterWhere( [ - 'id' => $this->id, - 'user_id' => $this->user_id, - 'delivery' => $this->delivery, - 'payment' => $this->payment, - 'status' => $this->status, + 'id' => $this->id, ] ); @@ -98,25 +110,63 @@ 'name', $this->name, ] - ) - ->andFilterWhere( - [ - 'like', - 'email', - $this->email, - ] - ) - ->andFilterWhere( - [ - 'like', - 'phone', - $this->phone, - ] - ); - if (!empty($this->date_range)) { + ); + $query->andFilterWhere( + [ + 'like', + 'email', + $this->email, + ] + ); + $query->andFilterWhere( + [ + 'like', + 'phone', + $this->phone, + ] + ); + $query->andFilterWhere( + [ + 'like', + 'body', + $this->body, + ] + ); + $query->andFilterWhere( + [ + 'like', + 'consignment', + $this->consignment, + ] + ); + $query->andFilterWhere( + [ + 'like', + 'declaration', + $this->declaration, + ] + ); + $query->andFilterWhere( + [ + 'label' => $this->label, + + ] + ); + $query->andFilterWhere( + [ + 'manager_id' => $this->manager_id, + + ] + ); + $query->andFilterWhere( + [ + 'delivery' => $this->delivery, + ] + ); + 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( [ '>=', diff --git a/models/TaxGroup.php b/models/TaxGroup.php index 2bc665f..1642ed4 100755 --- a/models/TaxGroup.php +++ b/models/TaxGroup.php @@ -117,8 +117,8 @@ 'is_filter' => 'Use in filter', 'sort' => 'Sort', 'display' => 'Display', - 'is_menu' => 'Отображать в меню', - 'level' => 'уровень', + 'is_menu' => 'Отображать в характеристиках', + 'level' => 'уровень', 'ppsition' => 'Позиция', ]; } diff --git a/views/order/_form.php b/views/order/_form.php index 488b9e7..52dc876 100755 --- a/views/order/_form.php +++ b/views/order/_form.php @@ -4,10 +4,12 @@ use artweb\artbox\ecommerce\models\Order; use artweb\artbox\ecommerce\models\OrderPayment; use artweb\artbox\ecommerce\models\OrderProduct; + use backend\models\SmsTemplate; use kartik\grid\GridView; 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; @@ -52,7 +54,17 @@ $('#order-phone, #order-phone2').mask('+38(000)000-00-00', { JS; $this->registerJs($js, View::POS_READY); - + + $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); +}); +JS; + + $this->registerJs($js, View::POS_READY); ?> @@ -65,9 +77,14 @@ JS; ) ?> $model->id, + ] + ), [ - 'class' => 'btn btn-info', + 'class' => $model->isNewRecord ? 'btn btn-info disabled' : 'btn btn-info', 'target' => '_blank', ] ) ?> @@ -206,20 +223,26 @@ JS; 'layout' => '{items}{pager}', 'columns' => [ 'id', - 'product_name', 'sku', + 'product_name', + 'productVariant.product.brand.lang.title', + 'productVariant.lang.title', + 'price', [ 'class' => 'kartik\grid\EditableColumn', 'attribute' => 'count', 'editableOptions' => [ - 'header' => \Yii::t('app', 'Количество'), - 'inputType' => kartik\editable\Editable::INPUT_SPIN, - 'options' => [ + 'header' => \Yii::t('app', 'Количество'), + 'inputType' => kartik\editable\Editable::INPUT_SPIN, + 'options' => [ 'pluginOptions' => [ 'min' => 0, 'max' => 5000, ], ], + 'pluginEvents' => [ + 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', + ], ], 'format' => [ 'decimal', @@ -227,6 +250,7 @@ JS; ], 'pageSummary' => false, ], + 'sum_cost', [ 'class' => 'yii\grid\ActionColumn', 'template' => '{delete}', @@ -316,3 +340,42 @@ JS; +
+
+
+
+
+
+
+ 'sms-template-selector', + 'name' => 'select-sms-template', + 'data' => ArrayHelper::map( + SmsTemplate::find() + ->asArray() + ->all(), + 'text', + 'title' + ), + 'options' => [ 'placeholder' => \Yii::t('app', 'Выберите шаблон') ], + 'pluginOptions' => [ + 'allowClear' => true, + ], + ] + ); + + ?> + + 5, + ] + ); + ?> +
+
diff --git a/views/order/index.php b/views/order/index.php index cc0d8e9..9869ae2 100755 --- a/views/order/index.php +++ b/views/order/index.php @@ -9,15 +9,19 @@ use artweb\artbox\ecommerce\models\Label; use artweb\artbox\ecommerce\models\Order; use artweb\artbox\ecommerce\models\OrderSearch; + use common\models\User; use kartik\daterange\DateRangePicker; use kartik\select2\Select2; use yii\data\ActiveDataProvider; + use yii\helpers\ArrayHelper; use yii\helpers\Html; use kartik\grid\GridView; use yii\helpers\StringHelper; use yii\helpers\Url; + use yii\web\JsExpression; use yii\web\View; use yii\widgets\ActiveForm; + use yii\widgets\Pjax; $this->title = 'Заказы'; $this->params[ 'breadcrumbs' ][] = $this->title; @@ -34,7 +38,7 @@ JS;

'btn btn-success' ]) ?>

- + $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, - ], - ] - ); + echo $searchForm->field($searchModel, 'label') + ->widget( + Select2::className(), + [ + '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, + ], + ] + ); ?>
$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, - ], - ] - ); + echo $searchForm->field($searchModel, 'delivery') + ->widget( + Select2::className(), + [ + '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, + ], + ] + ); +?> + +field($searchModel, 'sku') + ->widget( + Select2::className(), + [ + 'options' => [ 'placeholder' => 'Search for a product ...' ], + 'pluginOptions' => [ + 'allowClear' => true, + 'minimumInputLength' => 3, + 'language' => [ + 'errorLoading' => new JsExpression( + "function () { return 'Waiting for results...'; }" + ), + ], + 'ajax' => [ + 'url' => \yii\helpers\Url::to([ 'find-product' ]), + 'dataType' => 'json', + 'data' => new JsExpression( + 'function(params) { return {q:params.term}; }' + ), + ], + 'escapeMarkup' => new JsExpression( + 'function (markup) { return markup; }' + ), + 'templateResult' => new JsExpression( + 'function(data) { return data.sku; }' + ), + 'templateSelection' => new JsExpression( + 'function (data) { + if(data.sku == undefined) { + return "sku"; + } else { + return data.sku; + } + }' + ), + ], + ] + ); + ?> + +field($searchModel, 'manager_id') + ->dropDownList( + ArrayHelper::map( + User::find() + ->asArray() + ->all(), + 'id', + 'username' + ), + [ 'prompt' => \Yii::t('app', 'Выберите менеджера ...') ] + ) ?> + +field($searchModel, 'email') + ->textInput() ?> + +field($searchModel, 'declaration') + ->textInput() ?> + +field($searchModel, 'consignment') + ->textInput() ?> + +

'deadline', - 'content' => function($model) { - if ($model->deadline == ''){ + 'content' => function($model) { + if ($model->deadline == '') { return ''; } else { return \Yii::$app->formatter->asDate($model->deadline); } - } + }, ], 'name', 'total', @@ -165,6 +233,7 @@ JS; 'adress', [ 'attribute' => 'label', + 'filter' => false, 'value' => function($model) { /** * @var Order $modl @@ -199,3 +268,4 @@ JS; + -- libgit2 0.21.4