示例#1
0
 public function actionRegion($id = null)
 {
     if ($id) {
         $model = Geo::getOne($id);
         //получчаем количество розничных точек в регионе
         $col_apteki = Apteki::find()->where(['region_id' => $id])->count();
         //получаем количество Юр.лиц
         $col_ur_l = RegionUrL::find()->where(['id_reg' => $id])->count();
         $db = new Query();
         $db->from('region_ur_l');
         $db->InnerJoin('ur_l', 'id_ur = ur_l.id');
         $db->andWhere(['=', 'id_reg', $id]);
         $db->andWhere(['=', 'ur_l.regional_id', $model['regional_id']]);
         $col_ur_l_regpred = $db->count();
         //  $col_ur_l_regpred = RegionUrL::find()->where(['id_reg' => $id])->andWhere(['$model'=>])->count();
     } else {
         $model = Geo::getAll();
     }
     $region = new Geo();
     if ($_POST['Geo']) {
         $model->attributes = $_POST['Geo'];
         if ($model->validate() && $model->save()) {
             return $this->render('/edit/region', ['model' => $model, 'region' => $region, 'ok' => 1, 'col_apteki' => $col_apteki, 'col_ur_l' => $col_ur_l, 'col_ur_l_regpred' => $col_ur_l_regpred]);
         }
     }
     if ($id) {
         return $this->render('/edit/region', ['model' => $model, 'col_apteki' => $col_apteki, 'col_ur_l' => $col_ur_l, 'col_ur_l_regpred' => $col_ur_l_regpred]);
     } else {
         return $this->render('region', ['model' => $model]);
     }
 }
示例#2
0
 /**
  *Статистика по Реестру
  */
 public function actionStat()
 {
     $ur_l = Ur::find()->count();
     $ur_l_farmopeka = Ur::find()->where(['farmopeka' => '1'])->count();
     $ur_l_aau = Ur::find()->where(['aau' => '1'])->count();
     $apteki = Apteki::find()->count();
     $apteki_farmopeka = Apteki::find()->where(['farmopeka' => '1'])->count();
     $stat = new StatReestr();
     $stat->count_ur_l = $ur_l;
     $stat->count_ur_l_farmopeka = $ur_l_farmopeka;
     $stat->count_ur_l_aau = $ur_l_aau;
     $stat->count_apteki = $apteki;
     $stat->count_apteki_farmopeka = $apteki_farmopeka;
     print $stat->save();
 }
示例#3
0
 public function actionCoordinates()
 {
     $apteki = Apteki::find()->where('updated_at>= now() - INTERVAL 3 DAY')->orderBy(['updated_at' => 'ASC'])->limit(100)->all();
     foreach ($apteki as $apteka) {
         $url = "https://geocode-maps.yandex.ru/1.x/?format=json&geocode=Россия, " . $apteka['address'];
         $getUrl = json_decode(file_get_contents($url), true);
         $coordinates = $getUrl['response']['GeoObjectCollection']['featureMember']['0']['GeoObject']['Point']['pos'];
         print $apteka['address'];
         print $coordinates;
         print "<br>";
         $model = $apteki = Apteki::findOne($apteka['id']);
         $model->coordinates = $coordinates;
         $model->save();
         usleep(500000);
         //0.5 сек
     }
 }
示例#4
0
 public function actionEdit($id)
 {
     $user = Users::getOne($id);
     $status = $user['status'];
     $eng = Yii::$app->params['status_user_eng'][$status];
     if ($status == '3') {
         $users = Users::find()->select(['id', 'username'])->where(['status' => '2'])->all();
         $items = ArrayHelper::map($users, 'id', 'username');
     }
     if ($status == 2) {
         $count['ur'] = Ur::find()->where(['regional_id' => $id])->count();
         $count['apteki'] = Apteki::find()->where(['regional_id' => $id])->count();
     }
     if ($status == 3) {
         $count['ur'] = Ur::find()->where(['pi_id' => $id])->count();
         $count['apteki'] = Apteki::find()->where(['pi_id' => $id])->count();
     }
     if ($eng == "") {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     if (Yii::$app->request->post('Users')) {
         $user->attributes = Yii::$app->request->post('Users');
         $user->photo = UploadedFile::getInstance($user, 'photo');
         if ($user->validate() && $user->save()) {
             if ($user->photo && $user->photo->tempName) {
                 $imagefile = 'img/user/' . $user->id . '.jpg';
                 $imagefileTh = 'img/user/th/' . $user->id . '.jpg';
                 $user->photo->saveAs('img/user/' . $user->id . '.jpg');
                 $img = Image::getImagine()->open(Yii::getAlias($imagefile));
                 $size = $img->getSize();
                 $ratio = $size->getWidth() / $size->getHeight();
                 $width = 200;
                 $height = round($width / $ratio);
                 Image::thumbnail($imagefile, $width, $height)->save($imagefileTh, ['quality' => 90]);
                 $width = 1600;
                 $height = round($width / $ratio);
                 if ($size->getWidth() > 1600) {
                     Image::thumbnail($imagefile, $width, $height)->save($imagefile, ['quality' => 97]);
                 }
             }
             return $this->render($eng, ['model' => $user, 'items' => $items, 'id' => $id, 'status' => Yii::$app->params['status_user'][$status], 'ok' => 1, 'count' => $count]);
         }
     }
     return $this->render($eng, ['model' => $user, 'items' => $items, 'id' => $id, 'status' => Yii::$app->params['status_user'][$status], 'count' => $count]);
 }
示例#5
0
 public function actionUpdateOld($date = null, $apt)
 {
     //УДАЛИТьЬ ПОТОМ!
     // && $model->validate()
     if (\Yii::$app->request->post()) {
         $array = \Yii::$app->request->post();
         $date = (int) $array['date_y'] . '-' . (int) $array['date_m'] . '-' . (int) $array['date_d'];
         if (is_numeric($array['id'])) {
             $model = Visitors::findOne($array['id']);
         } else {
             $model = new Visitors();
         }
         $model->apteki_id = (int) $array['apteki_id'];
         $model->date = $date;
         $user_id = (int) $array['user_id'];
         if ($array['date_type']) {
             $model->date_type = 2;
         } else {
             $model->date_type = 1;
         }
         $model->otchet = $array['otchet'];
         if ($model->save()) {
             return $this->redirect(["/visitors/?user={$user_id}"]);
             //
         }
     }
     $apteka = Apteki::find()->where(['id' => $apt, 'farmopeka' => '1'])->one();
     if ($apteka['id']) {
         $visitors = Visitors::find()->andFilterWhere(['LIKE', 'date', $date])->andFilterWhere(['=', 'apteki_id', $apteka[id]])->one();
         if (!$visitors['date']) {
             $visitors['date'] = $date;
         }
     } else {
         throw new \yii\web\HttpException(404, 'Аптека не найдена или не входит в фармопеку');
     }
     return $this->render('update', ['apteka' => $apteka, 'visitors' => $visitors]);
 }
示例#6
0
 /**
  * Finds the Apteki model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Apteki the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Apteki::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#7
0
 /**
  * Updates an existing ValidationReport model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $model2 = ValidationReportViolation::find()->select('violation_id')->where(['report_id' => $id])->column();
     $model->user_id = \Yii::$app->user->identity->id;
     $UrRecords = Ur::find()->orderBy('name');
     if (\Yii::$app->user->identity->status == 2) {
         $UrRecords = $UrRecords->Where(['regional_id' => \Yii::$app->user->identity->id]);
     }
     if (\Yii::$app->user->identity->status == 3) {
         $UrRecords = $UrRecords->Where(['pi_id' => \Yii::$app->user->identity->id]);
     }
     $UrRecords = $UrRecords->all();
     if ($model->load(Yii::$app->request->post())) {
         // ValidationReportViolation::deleteAll("report_id = $model->report_id");
     }
     $ur_l = Apteki::findOne($model->apteka_id);
     $ur_l_id = $ur_l['ur_l_id'];
     $apteki = Apteki::find()->where(['ur_l_id' => $ur_l_id])->orderBy(['address' => 'desc'])->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         ValidationReportViolation::deleteAll(['report_id' => $model->id]);
         $post = Yii::$app->request->post();
         if ($post['v']) {
             foreach ($post['v'] as $key => $item) {
                 Yii::$app->db->createCommand()->insert('validation_report_violation', ['report_id' => $model->id, 'violation_id' => (int) $key])->execute();
             }
         }
         return $this->redirect(['index', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'UrRecords' => $UrRecords, 'model2' => $model2, 'ur_l_id' => $ur_l_id, 'apteki' => $apteki]);
     }
 }
示例#8
0
 public function actionTable()
 {
     if (\Yii::$app->user->identity->status == 1) {
         $users = Users::find()->where(['status' => 2])->orderBy('username')->all();
     } else {
         $users = Users::find()->where(['id' => \Yii::$app->user->identity->id])->orderBy('username')->all();
     }
     foreach ($users as $user) {
         $id = $user['id'];
         $db = new Query();
         $db->from(Ur::tableName());
         $db->select(['COUNT(*) AS count', 'id_reg', 'region.name']);
         $db->where(['=', 'ur_l.regional_id', $id]);
         $db->andWhere(['=', 'ur_l.plat', '1']);
         $db->innerJoin('region_ur_l', "region_ur_l.id_ur = ur_l.id");
         $db->innerJoin('region', "region.id = region_ur_l.id_reg");
         $db->groupBy('region_ur_l.id_reg');
         $db->orderBy('region.name ASC');
         $ur_region_array[$id] = $db->all();
         $db = new Query();
         $db->from(Apteki::tableName());
         $db->select(['COUNT(*) AS count', 'region.id', 'region.name']);
         $db->where(['=', 'apteki.regional_id', $id]);
         $db->innerJoin('region', "region.id = apteki.region_id");
         $db->groupBy('region.id');
         $db->orderBy('region.name ASC');
         $apteki_region_array[$id] = $db->all();
     }
     return $this->render('table', compact(['ur_region_array', 'apteki_region_array', 'users']));
 }
示例#9
0
 /**
  * Deletes an existing Ur model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     //  Apteki::deleteAll(['ur_l_id' => $id]); // Не логируется
     //Удаляем аптеки
     $aprdel = Apteki::find()->where(['ur_l_id' => $id])->all();
     foreach ($aprdel as $apt) {
         $customer = Apteki::findOne($apt['id']);
         $customer->delete();
     }
     //Удаляем регоны
     $regiondel = RegionUrL::find()->where(['id_ur' => $id])->all();
     foreach ($regiondel as $reg) {
         $customer2 = RegionUrL::findOne($reg['id']);
         $customer2->delete();
     }
     return $this->redirect(['/']);
 }
示例#10
0
 /**
  * пароль для аптеки
  */
 public function actionUpdate($id)
 {
     //   $this->layout = 'modal';
     //   $this->layout = 'modal';
     $model = SbSiteUsers::findOne(['apteki_id' => $id]);
     if ($model == null) {
         $model = new SbSiteUsers();
         $save = 1;
     }
     if (Yii::$app->request->isAjax) {
         $model->load($_POST);
         Yii::$app->response->format = 'json';
         return ActiveForm::validate($model);
     } elseif ($model->load($_POST)) {
         $model->apteki_id = $id;
         $model->su_domains = "sojuzpharma.ru";
         $model->su_pass = md5($model->password_simple);
         //Получаеи информацию об аптеки
         $apt = Apteki::findOne(['id' => $id]);
         $model->su_name = $apt['address'];
         $model->su_email = $apt['contact_mail'];
         if ($_POST['sendMail']) {
             \Yii::$app->mail->compose('apteki_pass', ['login' => $model->su_id, 'pass' => $model->password_simple, 'address' => $apt['address'], 'contact_face' => $apt['contact_face']])->setFrom([\Yii::$app->params['infoEmail'] => 'СоюзФарма'])->setTo($apt['contact_mail'])->setSubject('Для вашей аптеки заведена учетная запись')->send();
         }
         if ($model->save()) {
             if ($save) {
                 $model3 = SbSiteUsers::findOne(['apteki_id' => $id]);
                 $model3->su_login = $model->su_id;
                 $model3->save();
                 $model2 = new SbCatlinks();
                 $model2->link_cat_id = '21';
                 $model2->link_el_id = $model->su_id;
                 $model2->save();
             }
             return $this->redirect(['/apteki/update', 'id' => $model->apteki_id]);
             //  $row_id=(mysql_fetch_assoc(mysql_query('SELECT max(LAST_INSERT_ID(su_id)) AS id FROM sb_site_users ')));
             //  mysql_query("INSERT INTO sbuilder.sb_catlinks  (link_cat_id,link_el_id) values ('21','$id')");
         }
     } else {
         return $this->render('update', ['model' => $model, 'id' => $id]);
     }
 }