public function actionInfoWindow($userSessionId) { $session = UserSession::findOne($userSessionId); $stat = yii::$app->order->getStatByDatePeriod($session->start, $session->stop); $orders = Order::findAll(['date' > $session->start, 'date' < $session->stop]); return $this->renderPartial('info-window', ['module' => yii::$app->getModule('order'), 'session' => $session, 'stat' => $stat, 'orders' => $orders]); }
public function search($params) { $query = Order::find(); $query->joinWith('elementsRelation'); if ($elementTypes = yii::$app->request->get('element_types')) { $query->andFilterWhere(['order_element.model' => $elementTypes])->groupBy('order.id'); } $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'status' => $this->status, 'promocode' => $this->promocode, 'seller_user_id' => $this->seller_user_id]); $query->andFilterWhere(['like', 'client_name', $this->client_name])->andFilterWhere(['like', 'shipping_type_id', $this->shipping_type_id])->andFilterWhere(['like', 'payment_type_id', $this->payment_type_id])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'date', $this->date])->andFilterWhere(['like', 'time', $this->time]); if (yii::$app->request->get('promocode')) { $query->andWhere("promocode != ''"); $query->andWhere("promocode IS NOT NULL"); } if ($customField = yii::$app->request->get('order-custom-field')) { $orderIds = []; foreach ($customField as $id => $str) { if (!empty($str)) { if ($values = FieldValue::find()->select('order_id')->where(['field_id' => $id])->andWhere(['LIKE', 'value', $str])->all()) { foreach ($values as $value) { $orderIds[] = $value->order_id; } } } } if ($orderIds) { $query->andWhere(['order.id' => $orderIds]); } } if ($dateStart = yii::$app->request->get('date_start')) { $dateStart = date('Y-m-d', strtotime($dateStart)); if (!yii::$app->request->get('date_stop')) { $query->andWhere('DATE_FORMAT(date, "%Y-%m-%d") = :dateStart', [':dateStart' => $dateStart]); } else { $query->andWhere('date >= :dateStart', [':dateStart' => $dateStart]); } } else { if ($timeStart = yii::$app->request->get('time_start')) { $query->andWhere('date >= :timeStart', [':timeStart' => $timeStart]); } if ($timeStop = yii::$app->request->get('time_stop')) { if (urldecode($timeStop) == '0000-00-00 00:00:00') { $timeStop = date('Y-m-d H:i:s'); } $query->andWhere('date <= :timeStop', [':timeStop' => $timeStop]); } } if ($dateStop = yii::$app->request->get('date_stop')) { $dateStop = date('Y-m-d', strtotime($dateStop)); $query->andWhere('date <= :dateStop', [':dateStop' => $dateStop]); } return $dataProvider; }
public function run() { if ($this->types) { $paymentTypes = ArrayHelper::map(PaymentType::find()->where(['id' => $this->types])->all(), 'id', 'name'); } else { $paymentTypes = ArrayHelper::map(PaymentType::find()->all(), 'id', 'name'); } $report = []; $hasReport = false; foreach ($paymentTypes as $pid => $pname) { $query = Order::find()->where('date >= :dateStart AND date <= :dateStop', [':dateStart' => $this->dateStart, ':dateStop' => $this->dateStop]); $sum = $query->andWhere(['payment_type_id' => $pid])->distinct()->sum('cost'); $report[$pname] = $sum; if ($sum) { $hasReport = true; } } if (!$hasReport) { return ''; } return $this->render('report-payment-types', ['report' => $report, 'dateStart' => $this->dateStart, 'dateStop' => $this->dateStop]); }
public function getOrder() { return $this->hasOne(Order::className(), ['id' => 'order_id']); }
public function actionOrder($order_id = false) { $customServiceModel = new CustomService(); if ($customServiceModel->load(Yii::$app->request->post()) && $customServiceModel->save()) { yii::$app->cart->put($customServiceModel); if (yii::$app->request->post('ajax')) { die(json_encode(['result' => 'success'])); } else { \Yii::$app->session->setFlash('customServiceBuy', 'В корзине!'); } } if ($type = yii::$app->request->get('service-order-type')) { if (!in_array($type, ['net', 'table'])) { return $this->redirect('404'); } yii::$app->response->cookies->add(new \yii\web\Cookie(['name' => 'service-order-type', 'value' => $type])); } else { $type = yii::$app->request->cookies->get('service-order-type'); if (!$type) { $type = 'net'; } } $organization = false; $organizations = []; if (yii::$app->has('organization')) { $organization = yii::$app->organization->get(); $organizations = yii::$app->organization->getList(); } if ($organization) { $services = Service::find()->where('(calculator = "" OR calculator IS NULL) AND organization_id = :org_id', [':org_id' => $organization->id])->orderBy('sort DESC, id ASC')->all(); $categories = Category::find()->where(['organization_id' => $organization->id])->orderBy('sort DESC, id ASC')->all(); $complexes = Complex::find()->where(['organization_id' => $organization->id])->orderBy('sort DESC, id ASC')->all(); } else { $services = Service::find()->orderBy('sort DESC, id ASC')->all(); $categories = Category::find()->where('parent_id IS NULL OR parent_id = 0')->orderBy('sort DESC, id ASC')->all(); $complexes = Complex::find()->orderBy('sort DESC, id ASC')->all(); } $calculateServiceModel = Service::find()->where('calculator != ""')->all(); $priceModel = new Price(); $orderModel = new Order(); $paymentTypes = ArrayHelper::map(PaymentType::find()->orderBy('order DESC')->all(), 'id', 'name'); $shippingTypes = ArrayHelper::map(ShippingType::find()->orderBy('order DESC')->all(), 'id', 'name'); $prices = []; foreach ($priceModel::find()->all() as $price) { $prices[$price->service_type][$price->category_id][$price->service_id] = $price; } $this->getView()->registerJs('pistol88.service.propertyListUrl = "' . Url::toRoute(['/service/property/get-ajax-list']) . '";'); $this->getView()->registerJs('pistol88.service.searchClientByIdentUrl = "' . Url::toRoute(['/service/property/get-client-by-property']) . '";'); if ($order_id) { $order = Order::findOne($order_id); } else { $order = false; } return $this->render('order', ['order' => $order, 'organization' => $organization, 'organizations' => $organizations, 'type' => $type, 'customServiceModel' => $customServiceModel, 'calculateServiceModel' => $calculateServiceModel, 'prices' => $prices, 'services' => $services, 'complexes' => $complexes, 'categories' => $categories, 'orderModel' => $orderModel, 'priceModel' => $priceModel, 'paymentTypes' => $paymentTypes, 'shippingTypes' => $shippingTypes]); }
public function actionUpdateStatus() { if ($id = yii::$app->request->post('id')) { $model = Order::findOne($id); $model->status = yii::$app->request->post('status'); if ($model->save(false)) { die(json_encode(['result' => 'success'])); } else { die(json_encode(['result' => 'fail', 'error' => 'enable to save'])); } } throw new NotFoundHttpException('The requested page does not exist.'); }
public function get($id) { return OrderModel::findOne($id); }