public function searchListByAgent($params, $userId) { $query = Orders::find()->where(['user_id' => $userId]); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['updated_at' => SORT_DESC]]]); $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'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'user_id' => $this->user_id, 'created_at' => $this->created_at, 'repeated' => $this->repeated]); return $dataProvider; }
if (empty($session->get('creatingOrder')) || $session->get('creatingOrder') == 0) { ?> <?php echo Html::a('Создать заказ', ['create-order'], ['class' => 'btn btn-success']); ?> <?php } ?> </p> <p> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'updated_at')->label('Удалить из истории заявки ранее чем')->widget(DatePicker::className(), ['dateFormat' => 'yyyy-MM-dd 23:59:59', 'options' => ['class' => 'form-control', 'style' => 'width: 300px; margin-left: 10px;', 'placeholder' => 'Дата']]); ?> <?php echo Html::submitButton('Удалить', ['class' => 'btn btn-success']); ?> <?php ActiveForm::end(); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id', 'updated_at:datetime', ['class' => DataColumn::className(), 'label' => 'Товаров', 'value' => 'countProducts'], ['label' => 'Cумма (руб.)', 'attribute' => 'totalPriceForOrder', 'format' => 'text'], ['attribute' => 'status', 'value' => 'statusName', 'filter' => Orders::getStatusArray()], 'count_repeat', ['class' => ActionHistoryColumn::className()]]]); ?> </div>
/** * Отправка заказа из истории (с проверкой на изменение переменных сессии) * @param type $id - ИД заказа */ public function actionSendOrderFromHistoryPage($id) { $session = Yii::$app->session; $order = Orders::findOne(['id' => $id]); if ($session->get('idOrder') == $id) { $order->status = Orders::STATUS_SENDED; $session->set('creatingOrder', false); $session->set('idOrder', 0); } else { if ($order->status == Orders::STATUS_SENDED) { $countRepeat = $order->count_repeat; $order->count_repeat = $countRepeat + 1; } else { $order->status = Orders::STATUS_SENDED; } } $order->save(); $order->createDbf(); $session->setFlash('success', 'Заказ отправлен'); $this->redirect(['/main/orders/history']); }
use yii\grid\DataColumn; use app\modules\main\models\Orders; /* @var $this yii\web\View */ /* @var $searchModel app\modules\main\models\OrdersSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ /* @var $user app\modules\user\models\User */ $this->title = 'История заказов агента ' . $user->username . ''; $this->params['breadcrumbs'][] = $this->title; $this->params['menu'] = 6; $session = Yii::$app->session; ?> <div class="orders-index"> <h3><?php echo Html::encode($this->title); ?> </h3> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'updated_at', ['class' => DataColumn::className(), 'label' => 'Товаров', 'value' => 'countProducts'], ['label' => 'Cумма', 'attribute' => 'totalPriceForOrder'], ['attribute' => 'status', 'value' => 'statusName', 'filter' => Orders::getStatusArray()], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {confirmOrder}', 'buttons' => ['view' => function ($url, $model, $key) { return Html::a('<span class="glyphicon glyphicon-list-alt"></span>', ['/main/orderedproduct/confirm-checkout-by-admin', 'id' => $model->id], ['title' => 'Товары в заказе']); }, 'confirmOrder' => function ($url, $model, $key) { return Html::a('<span class="glyphicon glyphicon-circle-arrow-up"></span>', ['status-confirm', 'id' => $model->id], ['title' => 'Подтвердить заказ', 'data' => ['method' => 'post']]); }]]]]); ?> </div>
/** * Finds the Orders model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Orders the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Orders::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }