Ejemplo n.º 1
0
 public function search($params)
 {
     $query = Price::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'service_id' => $this->service_id, 'category_id' => $this->category_id, 'price' => $this->price]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 public function actionIndex()
 {
     $searchModel = new PriceSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     if ($prices = yii::$app->request->post('price')) {
         foreach ($prices as $categoryId => $types) {
             foreach ($types as $type => $services) {
                 foreach ($services as $serviceId => $price) {
                     $service = $type::findOne($serviceId);
                     if (!($priceModel = Price::find()->tariff($categoryId, $service)->one())) {
                         $priceModel = new Price();
                         $priceModel->category_id = $categoryId;
                         $priceModel->service_id = $serviceId;
                         $priceModel->service_type = $type;
                     }
                     $priceModel->price = $price;
                     $priceModel->save();
                 }
             }
         }
     }
     $priceModel = new Price();
     $prices = [];
     foreach ($priceModel::find()->all() as $price) {
         $prices[$price->service_type][$price->category_id][$price->service_id] = $price;
     }
     $organization = false;
     if (yii::$app->has('organization')) {
         $organization = yii::$app->organization->get();
     }
     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();
         $complexes = Complex::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();
     }
     if (yii::$app->has('organization')) {
         $organizations = yii::$app->organization->getList();
     } else {
         $organizations = [];
     }
     return $this->render('index', ['organization' => $organization, 'organizations' => $organizations, 'prices' => $prices, 'services' => $services, 'categories' => $categories, 'complexes' => $complexes, 'priceModel' => $priceModel, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }